diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 4ead67b282..ff4c2b51ac 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -195,9 +195,13 @@ module ActiveRecord if attrs.is_a?(Array) attrs.collect { |attr| create(attr) } else - create_record(attrs) do |record| - yield(record) if block_given? - insert_record(record) + ensure_owner_is_persisted! + + transaction do + build_record(attrs) do |record| + yield(record) if block_given? + insert_record(record) + end end end end @@ -423,11 +427,6 @@ module ActiveRecord raise NotImplementedError end - def create_record(attributes, &block) - ensure_owner_is_persisted! - transaction { build_record(attributes, &block) } - end - def build_record(attributes, &block) attributes = scoped.scope_for_create.merge(attributes) record = @reflection.build_association(attributes) |