mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Bring back +extra_conditions+. This effectively reverts 386b7bfd9d
This commit is contained in:
parent
6e18fa0375
commit
467d251c3d
2 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue