This project is archived and is in readonly mode.
Check joins when determining preloading of includes
-
Peter Wagenet
I've now added a test for this change.
-
Tiago Macedo
I found a bug in your code (it isn't specific to YOUR code, but it wasn't there before):
If you add this to your test:
posts = Post.find(:all, :select => "posts.*, authors.name AS test_name", :include => [ :comments, :author, :categories ], :limit => 1) assert_equal "David", posts.first.test_nameYou'll see that it fails. This will only happen using the old behaviour and a limit clause. This wasn't an issue before because the select clause was being discarded.
I think you'll have to check which tables are referenced in the select clause and force their eager load (in the same way that's being done for the conditions and order options)
-
Peter Wagenet
Turns out the real issue isn't the order or limit clause. It's the select clause. If the any of the select, conditions or order reference the include tables then the select clause ends up getting discarded. With my fix, the solution in any of these events is to use an additional joins parameter as shown above. I've changed my tests to be more generic.
-
Frederick Cheung
I've been working on this too. In that my patch is largely similar to yours, except that in the case when joins is a list/hash of association names I'm pulling the tables names straight out of the join dependency rather than turning the join dependency into a string and parsing that
-
Repository
- State changed from new to resolved
(from [c9ab7098be7bdd748c0f4a49c8ef015b4aad3108]) Ensure :include checks joins when determining if it can preload [#528 state:resolved] http://github.com/rails/rails/co...
