I''ve been here before and maybe I''m trying to do something that is not possible. I am trying to include tables that are associated to other tables in the actual include statement but not to the original table call. In this case the furnii table. this is my original query @furnii_from_furnii = Furni.find :all, :include =>[:raider, {:imageasset => :skin}], :conditions => ""+Furni.conditions_by_like(@search)+" OR " +Raider.conditions_by_like(@search) + "OR" +Skin.conditions_by_like(@search) + "" now I need to include 2 more tables skintype and skinstyle. these 2 tables are not associated to either furnii or imageassets but have an association to the skin table, which is associated to furnii through imageassets. can I group them in the same query? or do I have to do a separate query for skintype and skinstyle and then join it at the end? Sorry for my premature explanation. (I have simplified my models to reflect the above question) my models look like this: class Furni < ActiveRecord::Base belongs_to :imageasset end class Imageasset < ActiveRecord::Base has_one :skin end class Skin < ActiveRecord::Base belongs_to :imageasset belongs_to :skinstyle belongs_to :skintype end class Skintype < ActiveRecord::Base has_one :skin end class Skinstyle < ActiveRecord::Base has_one :skin end -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 24, 9:52 pm, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve been here before and maybe I''m trying to do something that is not > possible. I am trying to include tables that are associated to other > tables in the actual include statement but not to the original table > call. In this case the furnii table. > > this is my original query > > @furnii_from_furnii = Furni.find :all, :include =>[:raider, {:imageasset > => :skin}], :conditions => ""+Furni.conditions_by_like(@search)+" OR " > +Raider.conditions_by_like(@search) + "OR" > +Skin.conditions_by_like(@search) + "" > > now I need to include 2 more tables skintype and skinstyle. these 2 > tables are not associated to either furnii or imageassets but have an > association to the skin table, which is associated to furnii through > imageassets.Sure you can, you can nest includes as deep as you want. I''ve got some examples at http://www.spacevatican.org/2008/8/8/nested-includes-and-joins Fred> > can I group them in the same query? or do I have to do a separate query > for skintype and skinstyle and then join it at the end? > > Sorry for my premature explanation. > > (I have simplified my models to reflect the above question) > my models look like this: > > class Furni < ActiveRecord::Base > belongs_to :imageasset > end > > class Imageasset < ActiveRecord::Base > has_one :skin > end > > class Skin < ActiveRecord::Base > belongs_to :imageasset > belongs_to :skinstyle > belongs_to :skintype > end > > class Skintype < ActiveRecord::Base > has_one :skin > end > > class Skinstyle < ActiveRecord::Base > has_one :skin > end > -- > 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-/JYPxA39Uh5TLH3MbocFFw@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 Aug 24, 9:52�pm, Sam Ginko <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> +Skin.conditions_by_like(@search) + "" >> >> now I need to include 2 more tables skintype and skinstyle. these 2 >> tables are not associated to either furnii or imageassets but have an >> association to the skin table, which is associated to furnii through >> imageassets. > > Sure you can, you can nest includes as deep as you want. I''ve got some > examples at > http://www.spacevatican.org/2008/8/8/nested-includes-and-joins > > FredThanks for the link. I''m still not sure on how to join the 2 tables in question. I tried :include =>[:raider, {:imageasset => {:skintype =>:skin}] but that is not finding the association I tried :include =>[:raider, {:imageasset => {:skin =>:skintype}] that is not working ether. skin belongs to skintype so I''m not sure how to load it -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sam Ginko wrote:> I tried :include =>[:raider, {:imageasset => {:skintype =>:skin}] but > that is not finding the association > I tried :include =>[:raider, {:imageasset => {:skin =>:skintype}] that > is not working ether. > > skin belongs to skintype so I''m not sure how to load itPlease disregard the question above. Your examples cleared it all up. Thanks again for your help. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---