I have a simple one to many relation: class Precinct has_many :districts ... end I would like to find all Precincts that have no districts in a finder. Is that possible? I also am using the searchlogic gem (very nice) but even with that I could not concoct a one liner to do what I want. Any ideas would be greatly appreciated! - PIto -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 5, 2:05 pm, Pito Salas <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a simple one to many relation: > > class Precinct > has_many :districts > ... > end > > I would like to find all Precincts that have no districts in a finder. > Is that possible?You can do that with a left outer join (and then an isnull to filter for rows with no districts) Fred> > I also am using the searchlogic gem (very nice) but even with that I > could not concoct a one liner to do what I want. > > Any ideas would be greatly appreciated! > > - PIto > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Oct 5, 2:05�pm, Pito Salas <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> I have a simple one to many relation: >> >> class Precinct >> � has_many :districts >> ... >> end >> >> I would like to find all Precincts that have no districts in a finder. >> Is that possible? > > You can do that with a left outer join (and then an isnull to filter > for rows with no districts) > > FredThanks... I am not sure how to express that as Precinct.find_..... can you say? -- pito -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pito Salas wrote: [...]> Thanks... I am not sure how to express that as Precinct.find_..... can > you say?In cases like that, I usually find it helpful to write the SQL first, then transform it into ActiveRecord find syntax.> > -- pitoBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.