2009/5/12 Anthony Ward <rails-mailing-l...@andreas-s.net> > > Hi > > thanks works like a charm! > > but i'm just curious performance wise > when I look at mongrel it seems that there are two queries > first the children.all() > then for each record it does a new query for mother get name... > > now is that as quick compare to juts one query with a left join and get > all the data in children(). >
If you know you are going to be accessing the associated objects use :include in the find to tell Rails to fetch all the data in one query, so something like @children = Child.find(:all, :include => :mother) By the way, I think the class should be Child, the table children and the controller children_controller. Rails should know that children is the plural of child. If you are really building a database of family relationships then you might want to search for a thread here a few weeks ago about how to organise the db. There were some very interesting ideas discussed. Colin > > > Colin Law wrote: > > If you have set up the associations (belongs_to and has_many) then if > > you > > have a Child object child you can just say child.mother to get the > > mother. > > Similarly if you have a mother object you can say mother.children to get > > the > > children. It is all done by magic. > > Colin > > > > 2009/5/12 Anthony Ward <rails-mailing-l...@andreas-s.net> > > -- > 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---