Frederick Cheung wrote: > On Sep 22, 9:16�pm, Ben Johnson <[EMAIL PROTECTED]> > wrote: >> Thanks for your help. I am still somewhat confused though. >> >> So is the general rule of thumb to use joins on belongs to relationships >> and include on has_many. It looks as if joins returns flawed results is >> used on a has_many relationship. Is this correct? >> > No. Use :joins when you want a join. Use include when you want to > avoid the n+1 problem (ie you want rails to load and populate the > associations). > > Fred
Thanks for your help. I agree, I would prefer to use joins, but they do not return the proper results. It seems that joins return duplicate results: >> User.find(:all, :conditions => "orders.id > 1", :joins => :orders).size => 1254 >> User.find(:all, :conditions => "orders.id > 1", :include => :orders).size => 934 In the above example the first query is returning duplicate results. I am getting users with the same ID. I'm confused why it would return duplicate results. Any idea why this is? Seeing as this is a problem it seems that :include is my only option. Thanks. -- 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 [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

