Changeset 8947
- Timestamp:
- 02/29/08 04:36:54 (4 months ago)
- Files:
-
- branches/2-0-stable/activerecord/CHANGELOG (modified) (1 diff)
- branches/2-0-stable/activerecord/lib/active_record/associations/association_collection.rb (modified) (4 diffs)
- branches/2-0-stable/activerecord/lib/active_record/associations/association_proxy.rb (modified) (2 diffs)
- branches/2-0-stable/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2-0-stable/activerecord/CHANGELOG
r8866 r8947 1 1 *SVN* 2 3 * Improve associations performance by avoiding named block arguments. #11109 [adymo]4 2 5 3 * Ensure that modifying has_and_belongs_to_many actions clear the query cache. Closes #10840 [john.andrews] branches/2-0-stable/activerecord/lib/active_record/associations/association_collection.rb
r8866 r8947 44 44 45 45 # Calculate sum using SQL, not Enumerable 46 def sum(*args )47 calculate(:sum, *args ) { |*block_args| yield(*block_args) if block_given? }46 def sum(*args, &block) 47 calculate(:sum, *args, &block) 48 48 end 49 49 … … 122 122 end 123 123 124 def any? 124 def any?(&block) 125 125 if block_given? 126 method_missing(:any? ) { |*block_args| yield(*block_args) if block_given? }126 method_missing(:any?, &block) 127 127 else 128 128 !empty? … … 158 158 159 159 protected 160 def method_missing(method, *args )160 def method_missing(method, *args, &block) 161 161 if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 162 super { |*block_args| yield(*block_args) if block_given? }162 super 163 163 else 164 @reflection.klass.send(:with_scope, construct_scope) { 165 @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 166 } 164 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 167 165 end 168 166 end … … 190 188 private 191 189 192 def create_record(attrs )190 def create_record(attrs, &block) 193 191 ensure_owner_is_not_new 194 192 record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } 195 add_record_to_target_with_callbacks(record ) { |*block_args| yield(*block_args) if block_given? }196 end 197 198 def build_record(attrs )193 add_record_to_target_with_callbacks(record, &block) 194 end 195 196 def build_record(attrs, &block) 199 197 record = @reflection.klass.new(attrs) 200 add_record_to_target_with_callbacks(record ) { |*block_args| yield(*block_args) if block_given? }198 add_record_to_target_with_callbacks(record, &block) 201 199 end 202 200 branches/2-0-stable/activerecord/lib/active_record/associations/association_proxy.rb
r8866 r8947 79 79 end 80 80 81 def to_xml(options={}, &block)82 if load_target83 @target.to_xml(options, &block)84 end85 end86 87 81 protected 88 82 def dependent? … … 127 121 128 122 private 129 def method_missing(method, *args )123 def method_missing(method, *args, &block) 130 124 if load_target 131 @target.send(method, *args ) { |*block_args| yield(*block_args) if block_given? }125 @target.send(method, *args, &block) 132 126 end 133 127 end branches/2-0-stable/activerecord/lib/active_record/associations/has_many_through_association.rb
r8866 r8947 114 114 115 115 # Calculate sum using SQL, not Enumerable 116 def sum(*args )117 calculate(:sum, *args ) { |*block_args| yield(*block_args) if block_given? }116 def sum(*args, &block) 117 calculate(:sum, *args, &block) 118 118 end 119 119 … … 129 129 130 130 protected 131 def method_missing(method, *args )131 def method_missing(method, *args, &block) 132 132 if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 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 } 133 super 134 else 135 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 138 136 end 139 137 end