aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyan Bates <ryan@railscasts.com>2008-05-23 14:57:11 -0700
committerMichael Koziarski <michael@koziarski.com>2008-05-24 18:26:13 +1200
commit6cba97d2a449faf21aec9fe9d4434067e414226f (patch)
tree3c00a108230fe3471882678f362f4c138e6567df /activerecord/lib/active_record
parentb88ceb7dc8d31bdbea95ab4242bbdee17178cda9 (diff)
downloadrails-6cba97d2a449faf21aec9fe9d4434067e414226f.tar.gz
rails-6cba97d2a449faf21aec9fe9d4434067e414226f.tar.bz2
rails-6cba97d2a449faf21aec9fe9d4434067e414226f.zip
Create through associations can now work with blocks.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#248 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb10
1 files changed, 8 insertions, 2 deletions
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