I have 3 tables as such: Products (has many product_overruns, has many services) *id Product_Overruns (belongs to product) *product_id Services (Active Product) (belongs to product) * product_id I''d like to retrieve those services whose products have overruns defined for them, and can do so by joining them with sql (no inner join) to restrict the result sets to only those that have entries in all 3. When I try to create a named_scope in the Service class as such: named_scope :has_overruns, { :joins => [ :product, :product_overrun ] } .. it blows up with "ActiveRecord::ConfigurationError: Association named ''product_overrun'' was not found; perhaps you misspelled it?" "has_many :product_overruns, :through => :products" in the Service class has no effect. I''ve got a work-around using find_by_sql to get the ids of the desired services, but not exactly elegant. Thanks. -- 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 May 4, 5:42 pm, JohnnyC <gbull...-7Vr58nveOG2aMJb+Lgu22Q@public.gmane.org> wrote:> > I''d like to retrieve those services whose products have overruns > defined for them, and can do so by joining them with sql (no inner > join) to restrict the result sets to only those that have entries in > all 3. > > When I try to create a named_scope in the Service class as such: > > named_scope :has_overruns, { :joins => > [ :product, :product_overrun ] } > > .. it blows up with "ActiveRecord::ConfigurationError: Association > named ''product_overrun'' was not found; perhaps you misspelled it?"The syntax for a nested join is the same as the syntax for a nested include, in this case :joins => {:product => :product_overruns}. I''ve got some more example of the syntax expected at http://www.spacevatican.org/2008/8/8/nested-includes-and-joins Fred -- 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.
Thanks Fred. On May 4, 11:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 4, 5:42 pm, JohnnyC <gbull...-7Vr58nveOG2aMJb+Lgu22Q@public.gmane.org> wrote: > > > > > I''d like to retrieve those services whose products have overruns > > defined for them, and can do so by joining them with sql (no inner > > join) to restrict the result sets to only those that have entries in > > all 3. > > > When I try to create a named_scope in the Service class as such: > > > named_scope :has_overruns, { :joins => > > [ :product, :product_overrun ] } > > > .. it blows up with "ActiveRecord::ConfigurationError: Association > > named ''product_overrun'' was not found; perhaps you misspelled it?" > > The syntax for a nested join is the same as the syntax for a nested > include, in this case :joins => {:product => :product_overruns}. I''ve > got some more example of the syntax expected athttp://www.spacevatican.org/2008/8/8/nested-includes-and-joins > > Fred > > -- > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.