From 6cba97d2a449faf21aec9fe9d4434067e414226f Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 23 May 2008 14:57:11 -0700 Subject: Create through associations can now work with blocks. Signed-off-by: Michael Koziarski [#248 state:resolved] --- .../lib/active_record/associations/association_collection.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 2d3750e107..2f03197012 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -166,12 +166,18 @@ module ActiveRecord if attrs.is_a?(Array) attrs.collect { |attr| create(attr) } else - create_record(attrs) { |record| record.save } + create_record(attrs) do |record| + yield(record) if block_given? + record.save + end end end def create!(attrs = {}) - create_record(attrs) { |record| record.save! } + create_record(attrs) do |record| + yield(record) if block_given? + record.save! + end end # Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and -- cgit v1.2.3