From 386b7bfd9d78a6d8c8bc7cc4a310df806ad0ba57 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 2 Apr 2010 20:12:50 -0700 Subject: Remove an unused argument --- activerecord/lib/active_record/associations.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7406daf837..40022a614a 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1493,14 +1493,13 @@ 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, extra_conditions = nil) + def configure_dependency_for_has_many(reflection) if reflection.options.include?(:dependent) # Add polymorphic type if the :as option is present dependent_conditions = [] dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.table_name) if reflection.options[:conditions] - dependent_conditions << extra_conditions if extra_conditions dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") dependent_conditions = dependent_conditions.gsub('@', '\@') case reflection.options[:dependent] -- cgit v1.2.3 From 13004d4f849682772060371273fda3312dd3b884 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 2 Apr 2010 22:33:57 -0700 Subject: Make the query built by has_many ...., :dependent => :____ lazy since all the information is not really available yet. --- activerecord/lib/active_record/associations.rb | 72 ++++++++------------------ 1 file changed, 22 insertions(+), 50 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 40022a614a..7d628005dd 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1495,13 +1495,6 @@ module ActiveRecord # finder conditions. def configure_dependency_for_has_many(reflection) if reflection.options.include?(:dependent) - # Add polymorphic type if the :as option is present - dependent_conditions = [] - dependent_conditions << "#{reflection.primary_key_name} = \#{record.#{reflection.name}.send(:owner_quoted_id)}" - dependent_conditions << "#{reflection.options[:as]}_type = '#{base_class.name}'" if reflection.options[:as] - dependent_conditions << sanitize_sql(reflection.options[:conditions], reflection.table_name) if reflection.options[:conditions] - dependent_conditions = dependent_conditions.collect {|where| "(#{where})" }.join(" AND ") - dependent_conditions = dependent_conditions.gsub('@', '\@') case reflection.options[:dependent] when :destroy method_name = "has_many_dependent_destroy_for_#{reflection.name}".to_sym @@ -1510,51 +1503,30 @@ module ActiveRecord end before_destroy method_name when :delete_all - # before_destroy do |record| - # self.class.send(:delete_all_has_many_dependencies, - # record, - # "posts", - # Post, - # %@...@) # this is a string literal like %(...) - # end - # end - module_eval <<-CALLBACK - before_destroy do |record| - self.class.send(:delete_all_has_many_dependencies, - record, - "#{reflection.name}", - #{reflection.class_name}, - %@#{dependent_conditions}@) - end - CALLBACK + before_destroy do |record| + self.class.send(:delete_all_has_many_dependencies, + record, + reflection.name, + reflection.klass, + reflection.dependent_conditions(record, self.class)) + end when :nullify - # before_destroy do |record| - # self.class.send(:nullify_has_many_dependencies, - # record, - # "posts", - # Post, - # "user_id", - # %@...@) # this is a string literal like %(...) - # end - # end - module_eval <<-CALLBACK - before_destroy do |record| - self.class.send(:nullify_has_many_dependencies, - record, - "#{reflection.name}", - #{reflection.class_name}, - "#{reflection.primary_key_name}", - %@#{dependent_conditions}@) - end - CALLBACK - when :restrict - method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym - define_method(method_name) do - unless send(reflection.name).empty? - raise DeleteRestrictionError.new(reflection) - end + before_destroy do |record| + self.class.send(:nullify_has_many_dependencies, + record, + reflection.name, + reflection.klass, + reflection.primary_key_name, + reflection.dependent_conditions(record, self.class)) + end + when :restrict + method_name = "has_many_dependent_restrict_for_#{reflection.name}".to_sym + define_method(method_name) do + unless send(reflection.name).empty? + raise DeleteRestrictionError.new(reflection) end - before_destroy method_name + end + before_destroy method_name else raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, :nullify or :restrict (#{reflection.options[:dependent].inspect})" end -- cgit v1.2.3 From 467d251c3dcbd3e4dd1e785a21d63535b795a64c Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 3 Apr 2010 09:54:15 -0700 Subject: Bring back +extra_conditions+. This effectively reverts 386b7bfd9d78a6d8c8bc7cc4a310df806ad0ba57 --- activerecord/lib/active_record/associations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/associations.rb') 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 -- cgit v1.2.3