This project is archived and is in readonly mode.
has_many: collection.build doesn't allow passing a block to set attributes
Reported by Michael Trim | June 23rd, 2008 @ 08:49 PM
Given:
class Foo < ActiveRecord::Base
has_many :bars
end
class Bar < ActiveRecord::Base
end
It is possible to set attributes of a newly created Bar, using
@bar = Bar.new do |b|
b.something = "whatever"
end
@bar = Bar.create do |b|
b.something = "whatever"
end
@bar = Foo.bars.create do |b|
b.something = "whatever"
end
However, this doesn't work:
@bar = Foo.bars.build do |b|
b.something = "whatever"
end
Comments and changes to this ticket
-
Michael Trim June 23rd, 2008 @ 09:11 PM
Attached a patch with this functionality (implemented in the same way as for collection.create)
-
Pratik June 27th, 2008 @ 01:48 PM
- State changed from new to incomplete
- Tag set to activerecord, edge, enhancement, has_many, patch
The patch needs tests.
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>