diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-05-24 20:39:51 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-05-24 20:39:51 +0000 |
commit | c57c7210cd9216a72da8e9c7321d416ebfe1391e (patch) | |
tree | 8de460ee2f1125d8bbfe39d85a4166cadf7f6670 /activerecord/lib/active_record | |
parent | 4b9e67c5b9d9f751d633c787d24a1491f3ef498e (diff) | |
download | rails-c57c7210cd9216a72da8e9c7321d416ebfe1391e.tar.gz rails-c57c7210cd9216a72da8e9c7321d416ebfe1391e.tar.bz2 rails-c57c7210cd9216a72da8e9c7321d416ebfe1391e.zip |
Ensure that associations with :dependent => :delete_all respect :conditions option. Closes #8034 [danger, joshpeek, Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6827 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 0e8a48f2a0..e4bde6fc13 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1126,10 +1126,11 @@ module ActiveRecord # delete children, otherwise foreign key is set to NULL. # Add polymorphic type if the :as option is present - dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id}) - if reflection.options[:as] - dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'" - end + dependent_conditions = [] + dependent_conditions << "#{reflection.primary_key_name} = \#{record.quoted_id}" + dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] + dependent_conditions << sanitize_sql(reflection.options[:conditions]) if reflection.options[:conditions] + dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") case reflection.options[:dependent] when :destroy, true |