mirror of
https://github.com/github/rails.git
synced 2026-01-28 15:58:03 -05:00
Revert [8865], broke AP record identifier. Reopens #11109.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8874 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
* Improve associations performance by using symbol callbacks instead of string callbacks. #11108 [adymo]
|
||||
|
||||
* Improve associations performance by avoiding named block arguments. #11109 [adymo]
|
||||
|
||||
* Optimise the BigDecimal conversion code. #11110 [adymo]
|
||||
|
||||
* Introduce the :readonly option to all associations. Records from the association cannot be saved. #11084 [miloops]
|
||||
|
||||
@@ -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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user