aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-04-03 09:54:15 -0700
committerCarl Lerche <carllerche@mac.com>2010-04-03 09:54:15 -0700
commit467d251c3dcbd3e4dd1e785a21d63535b795a64c (patch)
treeaea2759a42e5632bea08e9baa30a5555ab42d907 /activerecord
parent6e18fa0375b7116328fbee920c074006962a52e8 (diff)
downloadrails-467d251c3dcbd3e4dd1e785a21d63535b795a64c.tar.gz
rails-467d251c3dcbd3e4dd1e785a21d63535b795a64c.tar.bz2
rails-467d251c3dcbd3e4dd1e785a21d63535b795a64c.zip
Bring back +extra_conditions+. This effectively reverts 386b7bfd9d78a6d8c8bc7cc4a310df806ad0ba57
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb6
-rw-r--r--activerecord/lib/active_record/reflection.rb3
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