diff options
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/reflection.rb | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7d628005dd..20a8754b7c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1493,7 +1493,7 @@ module ActiveRecord # The +extra_conditions+ parameter, which is not used within the main # Active Record codebase, is meant to allow plugins to define extra # finder conditions. - def configure_dependency_for_has_many(reflection) + def configure_dependency_for_has_many(reflection, extra_conditions = nil) if reflection.options.include?(:dependent) case reflection.options[:dependent] when :destroy @@ -1508,7 +1508,7 @@ module ActiveRecord record, reflection.name, reflection.klass, - reflection.dependent_conditions(record, self.class)) + reflection.dependent_conditions(record, self.class, extra_conditions)) end when :nullify before_destroy do |record| @@ -1517,7 +1517,7 @@ module ActiveRecord reflection.name, reflection.klass, reflection.primary_key_name, - reflection.dependent_conditions(record, self.class)) + reflection.dependent_conditions(record, self.class, extra_conditions)) end when :restrict method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 2a3f3f8713..0e48e229b3 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -277,11 +277,12 @@ module ActiveRecord !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) end - def dependent_conditions(record, base_class) + def dependent_conditions(record, base_class, extra_conditions) dependent_conditions = [] dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}" dependent_conditions << "#{options[:as]}_type = '#{base_class.name}'" if options[:as] dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions] + dependent_conditions << extra_conditions if extra_conditions dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") dependent_conditions = dependent_conditions.gsub('@', '\@') dependent_conditions |