I have a (legacyDB) table where ID is kept on updates, but the "active" column is set to 0 or 1. The primary key is a constraint of ID and Version ID Version Active Name 1 1 0 machineA 1 2 0 machineA 1 3 1 machineA so I query this with @machines = Machine.find( :all, :conditions => "Active=''1''") however in my join list <% @pools.each do |pool| %> <% for machine in pool.machines %><%= machine.Name %><% end %><% end %> I get the same machine listed for as many records as there are machines with that ID (which makes perfect sense to Rails because it''s the DB design that is nutty) if machineA has 3 entries (2 not active and 1 active) I get machineA listed 3 times for the pools that it''s in. is there a way to limit pool.machines to just the active machine? thanks -zac -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
James Ludlow
2006-Aug-24 20:46 UTC
[Rails] Re: join list where ID is repeated in one table?
On 8/24/06, Zac Elston <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have a (legacyDB) table where ID is kept on updates, but the "active" > column is set to 0 or 1. The primary key is a constraint of ID and > Version > > ID Version Active Name > 1 1 0 machineA > 1 2 0 machineA > 1 3 1 machineA > > so I query this with > @machines = Machine.find( :all, :conditions => "Active=''1''") > > however in my join list > > <% @pools.each do |pool| %> > <% for machine in pool.machines %><%= machine.Name %><% end %><% end %> > > I get the same machine listed for as many records as there are machines > with that ID (which makes perfect sense to Rails because it''s the DB > design that is nutty) > > if machineA has 3 entries (2 not active and 1 active) I get machineA > listed 3 times for the pools that it''s in. > > is there a way to limit pool.machines to just the active machine?I think what you''re looking for is the :conditions option on your model association. Check the docs for ActiveRecord. -- James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---