Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bring back +extra_conditions+. This effectively reverts 386b7bf

  • Loading branch information...
commit 467d251c3dcbd3e4dd1e785a21d63535b795a64c 1 parent 6e18fa0
Carl Lerche authored
View
6 activerecord/lib/active_record/associations.rb
@@ -1493,7 +1493,7 @@ def add_touch_callbacks(reflection, touch_attribute)
# 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 @@ def configure_dependency_for_has_many(reflection)
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 @@ def configure_dependency_for_has_many(reflection)
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
View
3  activerecord/lib/active_record/reflection.rb
@@ -277,11 +277,12 @@ def validate?
!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
Please sign in to comment.
Something went wrong with that request. Please try again.