This project is archived and is in readonly mode.
references_eager_loaded_tables? should search tables in :join clauses
-
Frederick Cheung
This looks juicy :-) With 2.2RC1 around the corner, would be great to see the patch!
-
David Stevenson
So... this is actually hard. It's not easy to write a REGEX that works to find all the joined in tables from a string. It's not as easy as looking for TABLE_NAME.FIELD_NAME like rails does for everything else.
Joseph and I have since disabled pre-2.1 style includes across our app. This turned out to be better for us than making rails "guess" better at which style of includes to use.
More and more, people will be switching away from old includes for performance reasons, so I think the better approach here might be to provide a global configuration on ActiveRecord to disable single-query includes. Naturally, it won't work for every query, but anyone who cares about performance will be optimizing all their queries to work anyway. Without the ability to disable these old-style includes completely, you're always going to be stuck trying to trick rails into believing that your query is safe. No matter how good we make the guessing system, there will always be incorrect guesses, so let's solve this problem at the core.
-
David Stevenson
Opened this ticket instead:
-
Rob Sanheim
What do you mean by "new include syntax" versus the "old include syntax" ?
-
David Stevenson
Sorry - new include syntax is not a syntax but an implementation. It's the process of preloading associations using a separate query for each level of the include chain.
The old include "syntax" created a single query to prefetch all the associated data. This was usually slower, but allowed you to use conditions on tables in the include chain.
-
Frederick Cheung
- State changed from new to duplicate
#528 Check joins when determining preloading of includes is all about this (and has patches too)