hi, I have a table hierarchy of level depth 3. e.g Node has one Blog has many Comments . I want to search nodes but also want all blogs has their comments. And I want this in one query. I know ther is :include for 1 level but for second what do I have to do? thanks in advance _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Well, you can denormalize your database, or you can write your own sql queries using find_by_sql. I''m not aware of any intrinsic Rails way to handle this situation. On 10/12/05, Onur Turgay <onurturgay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi, > > I have a table hierarchy of level depth 3. e.g Node has one Blog has many > Comments . I want to search nodes but also want all blogs has their > comments. And I want this in one query. I know ther is :include for 1 level > but for second what do I have to do? > > thanks in advance > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On 12-okt-2005, at 23:44, Kyle Maxwell wrote:> Well, you can denormalize your database, or you can write your own sql > queries using find_by_sql. I''m not aware of any intrinsic Rails way > to handle this situation.I don''t think you can currently do this in Rails. I mean, youca do it in one query but Rails will have a hard time hydrating records from the result. -- Julian "Julik" Tarkhanov
> I have a table hierarchy of level depth 3. e.g Node has one Blog has many > Comments . I want to search nodes but also want all blogs has their > comments. And I want this in one query. I know ther is :include for 1 level > but for second what do I have to do?Blog.find(:include=>[:node, :comments], :conditions=>[''nodes.foo = ?'', ''bar'']) Assuming a 1-1 relationship between nodes and blogs, that should give you what you need. Instead of using node, node.blog, and node.blog.comments, you''ll be using blog.node, blog, and blog.comments, but the data should still be the same.