From c57c7210cd9216a72da8e9c7321d416ebfe1391e Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 24 May 2007 20:39:51 +0000 Subject: 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 --- activerecord/lib/active_record/associations.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3