1
0
Fork 0
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:
Carl Lerche 2010-04-03 09:54:15 -07:00
parent 6e18fa0375
commit 467d251c3d
2 changed files with 5 additions and 4 deletions

View file

@ -1493,7 +1493,7 @@ module ActiveRecord
# The +extra_conditions+ parameter, which is not used within the main # The +extra_conditions+ parameter, which is not used within the main
# Active Record codebase, is meant to allow plugins to define extra # Active Record codebase, is meant to allow plugins to define extra
# finder conditions. # finder conditions.
def configure_dependency_for_has_many(reflection) def configure_dependency_for_has_many(reflection, extra_conditions = nil)
if reflection.options.include?(:dependent) if reflection.options.include?(:dependent)
case reflection.options[:dependent] case reflection.options[:dependent]
when :destroy when :destroy
@ -1508,7 +1508,7 @@ module ActiveRecord
record, record,
reflection.name, reflection.name,
reflection.klass, reflection.klass,
reflection.dependent_conditions(record, self.class)) reflection.dependent_conditions(record, self.class, extra_conditions))
end end
when :nullify when :nullify
before_destroy do |record| before_destroy do |record|
@ -1517,7 +1517,7 @@ module ActiveRecord
reflection.name, reflection.name,
reflection.klass, reflection.klass,
reflection.primary_key_name, reflection.primary_key_name,
reflection.dependent_conditions(record, self.class)) reflection.dependent_conditions(record, self.class, extra_conditions))
end end
when :restrict when :restrict
method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym

View file

@ -277,11 +277,12 @@ module ActiveRecord
!options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many) !options[:validate].nil? ? options[:validate] : (options[:autosave] == true || macro == :has_many)
end end
def dependent_conditions(record, base_class) def dependent_conditions(record, base_class, extra_conditions)
dependent_conditions = [] dependent_conditions = []
dependent_conditions << "#{primary_key_name} = #{record.send(name).send(:owner_quoted_id)}" 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 << "#{options[:as]}_type = '#{base_class.name}'" if options[:as]
dependent_conditions << klass.send(:sanitize_sql, options[:conditions]) if options[:conditions] 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.collect {|where| "(#{where})" }.join(" AND ")
dependent_conditions = dependent_conditions.gsub('@', '\@') dependent_conditions = dependent_conditions.gsub('@', '\@')
dependent_conditions dependent_conditions