Changeset 8865
- Timestamp:
- 02/14/08 07:24:09 (3 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/association_collection.rb (modified) (4 diffs)
- trunk/activerecord/lib/active_record/associations/association_proxy.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8864 r8865 1 1 *SVN* 2 3 * Improve associations performance by avoiding named block arguments. #11109 [adymo] 2 4 3 5 * Introduce the :readonly option to all associations. Records from the association cannot be saved. #11084 [miloops] trunk/activerecord/lib/active_record/associations/association_collection.rb
r8049 r8865 44 44 45 45 # Calculate sum using SQL, not Enumerable 46 def sum(*args , &block)47 calculate(:sum, *args , &block)46 def sum(*args) 47 calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } 48 48 end 49 49 … … 122 122 end 123 123 124 def any? (&block)124 def any? 125 125 if block_given? 126 method_missing(:any? , &block)126 method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } 127 127 else 128 128 !empty? … … 158 158 159 159 protected 160 def method_missing(method, *args , &block)160 def method_missing(method, *args) 161 161 if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 162 super 162 super { |*block_args| yield(*block_args) if block_given? } 163 163 else 164 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 164 @reflection.klass.send(:with_scope, construct_scope) { 165 @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 166 } 165 167 end 166 168 end … … 188 190 private 189 191 190 def create_record(attrs , &block)192 def create_record(attrs) 191 193 ensure_owner_is_not_new 192 194 record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } 193 add_record_to_target_with_callbacks(record , &block)194 end 195 196 def build_record(attrs , &block)195 add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } 196 end 197 198 def build_record(attrs) 197 199 record = @reflection.klass.new(attrs) 198 add_record_to_target_with_callbacks(record , &block)200 add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } 199 201 end 200 202 trunk/activerecord/lib/active_record/associations/association_proxy.rb
r8864 r8865 78 78 end 79 79 80 def to_xml(options={}, &block) 81 if load_target 82 @target.to_xml(options, &block) 83 end 84 end 85 80 86 protected 81 87 def dependent? … … 121 127 122 128 private 123 def method_missing(method, *args , &block)129 def method_missing(method, *args) 124 130 if load_target 125 @target.send(method, *args , &block)131 @target.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 126 132 end 127 133 end trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r8790 r8865 114 114 115 115 # Calculate sum using SQL, not Enumerable 116 def sum(*args , &block)117 calculate(:sum, *args , &block)116 def sum(*args) 117 calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } 118 118 end 119 119 … … 129 129 130 130 protected 131 def method_missing(method, *args , &block)131 def method_missing(method, *args) 132 132 if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 133 super 134 else 135 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 133 super { |*block_args| yield(*block_args) if block_given? } 134 else 135 @reflection.klass.send(:with_scope, construct_scope) { 136 @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 137 } 136 138 end 137 139 end