From bc4edca7b178bcac4d259809e965368e30a692a8 Mon Sep 17 00:00:00 2001 From: Derek Kraan Date: Fri, 11 Jan 2013 12:29:30 -0500 Subject: Fix .update_all and .delete_all when using a condition on a joined table in a default_scope. `Model.joins(...).where(condition_on_joined_table).update_all` / `delete_all` worked, but the same operation implemented with a default_scope generated a SQL error because ActiveRecord ignored the join but implemented the where condition anyways. --- activerecord/lib/active_record/relation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 6ec5cf3e18..0718c5076e 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -276,7 +276,7 @@ module ActiveRecord stmt.table(table) stmt.key = table[primary_key] - if joins_values.any? + if with_default_scope.joins_values.any? @klass.connection.join_to_update(stmt, arel) else stmt.take(arel.limit) @@ -401,7 +401,7 @@ module ActiveRecord stmt = Arel::DeleteManager.new(arel.engine) stmt.from(table) - if joins_values.any? + if with_default_scope.joins_values.any? @klass.connection.join_to_delete(stmt, arel, table[primary_key]) else stmt.wheres = arel.constraints -- cgit v1.2.3