diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-02-14 00:58:34 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-02-14 01:40:31 +0000 |
commit | 641a3068ea11c20e09358d6911404a265da32a9f (patch) | |
tree | 6ef640674f7a25317944e3f4c98cc6b23e03b484 /activerecord/lib | |
parent | 686418c65754701b9cdc213de4b6905f465fdc60 (diff) | |
download | rails-641a3068ea11c20e09358d6911404a265da32a9f.tar.gz rails-641a3068ea11c20e09358d6911404a265da32a9f.tar.bz2 rails-641a3068ea11c20e09358d6911404a265da32a9f.zip |
Don't pass the block through build_record
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index e391d9cce6..a850cf39cd 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -59,21 +59,21 @@ module ActiveRecord if attributes.is_a?(Array) attributes.collect { |attr| build(attr, &block) } else - build_record(attributes) do |record| - block.call(record) if block_given? + add_record_to_target_with_callbacks(build_record(attributes)) do |record| + yield(record) if block_given? set_owner_attributes(record) end end end - def create(attrs = {}) - if attrs.is_a?(Array) - attrs.collect { |attr| create(attr) } + def create(attributes = {}) + if attributes.is_a?(Array) + attributes.collect { |attr| create(attr) } else ensure_owner_is_persisted! transaction do - build_record(attrs) do |record| + add_record_to_target_with_callbacks(build_record(attributes)) do |record| yield(record) if block_given? insert_record(record) end @@ -427,10 +427,8 @@ module ActiveRecord raise NotImplementedError end - def build_record(attributes, &block) - attributes = scoped.scope_for_create.merge(attributes) - record = @reflection.build_association(attributes) - add_record_to_target_with_callbacks(record, &block) + def build_record(attributes) + @reflection.build_association(scoped.scope_for_create.merge(attributes)) end def delete_or_destroy(records, method) |