aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-04 03:19:50 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-04 03:19:50 +0000
commitc36f8111a6e7f305adc8eac87ea006e2517b93df (patch)
tree640742120fb4c716c6eb4cab9a27f1b2f683a462
parent25db1fc2014905d00795231dab2068f7a3497b04 (diff)
downloadrails-c36f8111a6e7f305adc8eac87ea006e2517b93df.tar.gz
rails-c36f8111a6e7f305adc8eac87ea006e2517b93df.tar.bz2
rails-c36f8111a6e7f305adc8eac87ea006e2517b93df.zip
pdate_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. Closes #10686.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8554 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb4
-rwxr-xr-xactiverecord/test/base_test.rb7
3 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index a6e963bebe..7d5771222b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* update_all ignores scoped :order and :limit, so post.comments.update_all doesn't try to include the comment order in the update statement. #10686 [Brendan Ribera]
+
* Added ActiveRecord::Base.cache_key to make it easier to cache Active Records in combination with the new ActiveSupport::Cache::* libraries [DHH]
* Make sure CSV fixtures are compatible with ruby 1.9's new csv implementation. [JEG2]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index d784f59d11..06d21f5525 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -680,8 +680,8 @@ module ActiveRecord #:nodoc:
sql = "UPDATE #{table_name} SET #{sanitize_sql_for_assignment(updates)} "
scope = scope(:find)
add_conditions!(sql, conditions, scope)
- add_order!(sql, options[:order], scope)
- add_limit!(sql, options, scope)
+ add_order!(sql, options[:order], nil)
+ add_limit!(sql, options, nil)
connection.update(sql, "#{name} Update")
end
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 5f8f1537d9..b140e9ce54 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -596,6 +596,13 @@ class BasicsTest < Test::Unit::TestCase
end
end
+ def test_update_all_ignores_order_limit_from_association
+ author = Author.find(1)
+ assert_nothing_raised do
+ assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all("body = 'bulk update!'")
+ end
+ end
+
def test_update_many
topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
updated = Topic.update(topic_data.keys, topic_data.values)