aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-03-07 00:04:06 +0000
committerJon Leighton <j@jonathanleighton.com>2011-03-07 00:04:20 +0000
commitcee3f9b36d01e6d54e0bd4c2fd06bee369bfff12 (patch)
tree8a7ca5843f7ca9f1d254cc8351672c936054cbab /activerecord/test/cases/relations_test.rb
parent5dc1fb39dde569c2633e067cdc895ddc56dd3482 (diff)
downloadrails-cee3f9b36d01e6d54e0bd4c2fd06bee369bfff12.tar.gz
rails-cee3f9b36d01e6d54e0bd4c2fd06bee369bfff12.tar.bz2
rails-cee3f9b36d01e6d54e0bd4c2fd06bee369bfff12.zip
Referencing a table via the ON condition in a join should force that table to be eager-loaded via a JOIN rather than via subsequent queries.
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 54537f11a8..ac586e2a63 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -850,4 +850,19 @@ class RelationTest < ActiveRecord::TestCase
def test_primary_key
assert_equal "id", Post.scoped.primary_key
end
+
+ def test_eager_loading_with_conditions_on_joins
+ scope = Post.includes(:comments)
+
+ # This references the comments table, and so it should cause the comments to be eager
+ # loaded via a JOIN, rather than by subsequent queries.
+ scope = scope.joins(
+ Post.arel_table.create_join(
+ Post.arel_table,
+ Post.arel_table.create_on(Comment.arel_table[:id].eq(3))
+ )
+ )
+
+ assert scope.eager_loading?
+ end
end