You'll have to give us the model relationship and sql generated before we can begin to answer this question unfortunately.
rabble
2009-03-27 20:44:44
You'll have to give us the model relationship and sql generated before we can begin to answer this question unfortunately.
The reason they generate two different SQL queries is that Rails, by default, tries to optimize your SQL queries for fewer joins. When you include a list of conditions as part of your find that require the use of other tables then of course the resulting SQL has to include a join. But if all you're asking to do is to pre-populate objects with relationships to the objects you're retrieving then Rails figures it's more efficient to perform several fast queries rather than one big slow query.
Note that this does not cause an N+1 problem, because Rails will try to load all of the associated records in a single query.