Permalink
Browse files

propogate bind values collected in arel to SQL generation

  • Loading branch information...
1 parent dbc8c0e commit 85f3a57a57b3c6d105e35936bf3ee972dc652902 @tenderlove tenderlove committed Apr 11, 2014
View
3 activerecord/lib/active_record/relation.rb
@@ -326,7 +326,8 @@ def update_all(updates)
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.
View
8 activerecord/test/cases/relations_test.rb
@@ -864,6 +864,14 @@ def test_count_with_distinct
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
View
2 activerecord/test/models/post.rb
@@ -40,6 +40,8 @@ def first_comment
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

0 comments on commit 85f3a57

Please sign in to comment.