diff options
author | Jason Dew <jason.dew@gmail.com> | 2008-06-27 12:25:26 -0400 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-14 02:24:12 +0100 |
commit | c6f397c5cecf183680c191dd2128c0a96c5b9399 (patch) | |
tree | 574b28103b2f9cb416cb7be9304f1a3f2adfc0d7 /activerecord/lib | |
parent | d72c66532f959846cdc2d7fb1dc1ef6ba87bdcb1 (diff) | |
download | rails-c6f397c5cecf183680c191dd2128c0a96c5b9399.tar.gz rails-c6f397c5cecf183680c191dd2128c0a96c5b9399.tar.bz2 rails-c6f397c5cecf183680c191dd2128c0a96c5b9399.zip |
Add block syntax to HasManyAssociation#build. [#502 state:resolve]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index eb39714909..04be59e89d 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -78,11 +78,14 @@ module ActiveRecord @loaded = false end - def build(attributes = {}) + def build(attributes = {}, &block) if attributes.is_a?(Array) - attributes.collect { |attr| build(attr) } + attributes.collect { |attr| build(attr, &block) } else - build_record(attributes) { |record| set_belongs_to_association_for(record) } + build_record(attributes) do |record| + block.call(record) if block_given? + set_belongs_to_association_for(record) + end end end |