Skip to content

Commit

Permalink
2-0-stable: Revert [8866]
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8947 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Feb 29, 2008
1 parent 833d3e4 commit 0a1deae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
2 changes: 0 additions & 2 deletions activerecord/CHANGELOG
@@ -1,7 +1,5 @@
*SVN*

* Improve associations performance by avoiding named block arguments. #11109 [adymo]

* Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews]

* Fix issue where Table#references doesn't pass a :null option to a *_type attribute for polymorphic associations. Closes #10753 [railsjitsu]
Expand Down
Expand Up @@ -43,8 +43,8 @@ def delete_all
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+.
Expand Down Expand Up @@ -121,9 +121,9 @@ def empty?
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
Expand Down Expand Up @@ -157,13 +157,11 @@ def replace(other_array)


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) {
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
}
@reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
end
end

Expand All @@ -189,15 +187,15 @@ def find_target

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)
Expand Down
10 changes: 2 additions & 8 deletions activerecord/lib/active_record/associations/association_proxy.rb
Expand Up @@ -78,12 +78,6 @@ def inspect
@target.inspect
end

def to_xml(options={}, &block)
if load_target
@target.to_xml(options, &block)
end
end

protected
def dependent?
@reflection.options[:dependent]
Expand Down Expand Up @@ -126,9 +120,9 @@ def merge_options_from_reflection!(options)
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

Expand Down
Expand Up @@ -113,8 +113,8 @@ def size
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)
Expand All @@ -128,13 +128,11 @@ def count(*args)
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) {
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? }
}
@reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) }
end
end

Expand Down

0 comments on commit 0a1deae

Please sign in to comment.