diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-11 16:14:51 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-11 16:14:51 -0700 |
commit | 85f3a57a57b3c6d105e35936bf3ee972dc652902 (patch) | |
tree | bff7790eaeb0c336d24ebca1af93e9b3a9e33788 /activerecord | |
parent | dbc8c0ee36ddda7c27a375c78bbdb989fd30c298 (diff) | |
download | rails-85f3a57a57b3c6d105e35936bf3ee972dc652902.tar.gz rails-85f3a57a57b3c6d105e35936bf3ee972dc652902.tar.bz2 rails-85f3a57a57b3c6d105e35936bf3ee972dc652902.zip |
propogate bind values collected in arel to SQL generation
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index a0e84201be..5b635ca7c1 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -326,7 +326,8 @@ module ActiveRecord stmt.wheres = arel.constraints end - @klass.connection.update stmt, 'SQL', bind_values + bvs = bind_values + arel.bind_values + @klass.connection.update stmt, 'SQL', bvs end # Updates an object (or multiple objects) and saves it to the database, if validations pass. diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 662e374ddd..dc196f4432 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -864,6 +864,14 @@ class RelationTest < ActiveRecord::TestCase assert_equal 11, posts.distinct(false).select(:comments_count).count end + def test_update_all_with_scope + tag = Tag.first + Post.tagged_with(tag.id).update_all title: "rofl" + list = Post.tagged_with(tag.id).all.to_a + assert_operator list.length, :>, 0 + list.each { |post| assert_equal 'rofl', post.title } + end + def test_count_explicit_columns Post.update_all(:comments_count => nil) posts = Post.all diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 099e039255..d9ecaee1d9 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -40,6 +40,8 @@ class Post < ActiveRecord::Base scope :with_comments, -> { preload(:comments) } scope :with_tags, -> { preload(:taggings) } + scope :tagged_with, ->(id) { joins(:taggings).where(taggings: { tag_id: id }) } + has_many :comments do def find_most_recent order("id DESC").first |