aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-06-03 21:51:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-06-03 21:51:57 +0000
commitd016d9a6d4d6f998bc4feb2c63908bb75a1529e3 (patch)
treeffe72c8854acc396b67d792de872d102bbca96fb /activerecord
parent2fbcae1912b1b6102790ef28f06c2d2a51e72828 (diff)
downloadrails-d016d9a6d4d6f998bc4feb2c63908bb75a1529e3.tar.gz
rails-d016d9a6d4d6f998bc4feb2c63908bb75a1529e3.tar.bz2
rails-d016d9a6d4d6f998bc4feb2c63908bb75a1529e3.zip
Fixed usage of :limit and with_scope when the association in scope is a 1:m (closes #5208) [alex@purefiction.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4422 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb2
-rwxr-xr-xactiverecord/test/base_test.rb8
3 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index b2f4afd24f..73e6e88dfe 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed usage of :limit and with_scope when the association in scope is a 1:m #5208 [alex@purefiction.net]
+
* Fixed migration trouble with SQLite when NOT NULL is used in the new definition #5215 [greg@lapcominc.com]
* Fixed problems with eager loading and counting on SQL Server #5212 [kajism@yahoo.com]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index ff10763cbf..d0bc72fcaf 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1145,7 +1145,7 @@ module ActiveRecord
add_joins!(sql, options, scope)
add_conditions!(sql, options[:conditions], scope)
- add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && options[:limit]
+ add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
sql << "ORDER BY #{options[:order]} " if options[:order]
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 5a6870faa3..e13a6b81c6 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1195,6 +1195,14 @@ class BasicsTest < Test::Unit::TestCase
assert scoped_developers.include?(developers(:david))
end
+ def test_scoped_find_limit_offset_including_has_many_association
+ topics = Topic.with_scope(:find => {:limit => 1, :offset => 1, :include => :replies}) do
+ Topic.find(:all, :order => "topics.id")
+ end
+ assert_equal 1, topics.size
+ assert_equal 2, topics.first.id
+ end
+
def test_base_class
assert LoosePerson.abstract_class?
assert !LooseDescendant.abstract_class?