From c55120c8e6922146fa50bf1e4f4d87d4820e09dc Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 15 Feb 2008 21:47:27 +0000 Subject: Revert [8865], broke AP record identifier. Reopens #11109. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8874 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../associations/association_collection.rb | 26 ++++++++++------------ .../associations/association_proxy.rb | 10 ++------- .../associations/has_many_through_association.rb | 12 +++++----- 3 files changed, 19 insertions(+), 29 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 359e27de3b..c993eb07fd 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -43,8 +43,8 @@ module ActiveRecord end # Calculate sum using SQL, not Enumerable - def sum(*args) - calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } + def sum(*args, &block) + calculate(:sum, *args, &block) end # Remove +records+ from this association. Does not destroy +records+. @@ -121,9 +121,9 @@ module ActiveRecord size.zero? end - def any? + def any?(&block) if block_given? - method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } + method_missing(:any?, &block) else !empty? end @@ -157,13 +157,11 @@ module ActiveRecord protected - def method_missing(method, *args) + def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super { |*block_args| yield(*block_args) if block_given? } + super else - @reflection.klass.send(:with_scope, construct_scope) do - @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } - end + @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } end end @@ -189,15 +187,15 @@ module ActiveRecord private - def create_record(attrs) + def create_record(attrs, &block) ensure_owner_is_not_new record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } - add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } + add_record_to_target_with_callbacks(record, &block) end - def build_record(attrs) + def build_record(attrs, &block) record = @reflection.klass.new(attrs) - add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } + add_record_to_target_with_callbacks(record, &block) end def add_record_to_target_with_callbacks(record) @@ -239,4 +237,4 @@ module ActiveRecord end end -end \ No newline at end of file +end diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 2f9ba31786..9fc0d44a01 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -77,12 +77,6 @@ module ActiveRecord @target.inspect end - def to_xml(options={}, &block) - if load_target - @target.to_xml(options, &block) - end - end - protected def dependent? @reflection.options[:dependent] @@ -126,9 +120,9 @@ module ActiveRecord end private - def method_missing(method, *args) + def method_missing(method, *args, &block) if load_target - @target.send(method, *args) { |*block_args| yield(*block_args) if block_given? } + @target.send(method, *args, &block) end end diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 81ec428d34..94842f424d 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -113,8 +113,8 @@ module ActiveRecord end # Calculate sum using SQL, not Enumerable - def sum(*args) - calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } + def sum(*args, &block) + calculate(:sum, *args, &block) end def count(*args) @@ -128,13 +128,11 @@ module ActiveRecord end protected - def method_missing(method, *args) + def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super { |*block_args| yield(*block_args) if block_given? } + super else - @reflection.klass.send(:with_scope, construct_scope) do - @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } - end + @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } end end -- cgit v1.2.3