aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul <paul@odysseus.(none)>2008-11-26 15:21:12 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-11-26 15:25:39 +0100
commit9a4d557713acb0fc8e80f61af18094034aca029a (patch)
tree4fb39be87214bdb8fea3e263cae1484823562b97
parent17940a82e8cb0ed278e1552b943dd033763978a1 (diff)
downloadrails-9a4d557713acb0fc8e80f61af18094034aca029a.tar.gz
rails-9a4d557713acb0fc8e80f61af18094034aca029a.tar.bz2
rails-9a4d557713acb0fc8e80f61af18094034aca029a.zip
Ensure hash conditions on referenced tables are considered when eager loading with limit/offset. [#1404 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rwxr-xr-xactiverecord/lib/active_record/associations.rb1
-rw-r--r--activerecord/test/cases/associations/eager_test.rb20
2 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 63e28a43ab..0546b76c63 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1733,6 +1733,7 @@ module ActiveRecord
case cond
when nil then all
when Array then all << cond.first
+ when Hash then all << cond.keys
else all << cond
end
end
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index a4f1f65f9a..3c8408d14b 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -385,12 +385,28 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal count, posts.size
end
- def test_eager_with_has_many_and_limit_ond_high_offset
+ def test_eager_with_has_many_and_limit_and_high_offset
posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ])
assert_equal 0, posts.size
end
- def test_count_eager_with_has_many_and_limit_ond_high_offset
+ def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions
+ assert_queries(1) do
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10,
+ :conditions => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ])
+ assert_equal 0, posts.size
+ end
+ end
+
+ def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
+ assert_queries(1) do
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10,
+ :conditions => { 'authors.name' => 'David', 'comments.body' => 'go crazy' })
+ assert_equal 0, posts.size
+ end
+ end
+
+ def test_count_eager_with_has_many_and_limit_and_high_offset
posts = Post.count(:all, :include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => [ "authors.name = ?", 'David' ])
assert_equal 0, posts
end