This project is archived and is in readonly mode.
nested attributes vs before_save
Reported by Marcin Mańk | October 18th, 2009 @ 07:07 PM | in 2.3.6
When a nested attribute class returns false in its
before_save hook, the main class still saves, and the child object
silently disappears, and save returns true. Observe:
# user.rb
class User < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts
end
#post.rb
class Post < ActiveRecord::Base
belongs_to :user
before_save :return_false
def return_false
false
end
end
# in console
>> User.new(:name=>'bug2', :posts_attributes=>[:body=>'test2']).save!
=> true
>> User.all
=> [#<User id: 4, name: "bug2">]
>> Post.all
=> []
I think it should throw an exception (or return false in case of "save" method)
Comments and changes to this ticket
-
Marcin Mańk October 30th, 2009 @ 06:52 PM
- Tag changed from attributes, nested to accepts_nested_attributes_for, before
-
Eloy Duran December 30th, 2009 @ 07:50 PM
- Assigned user set to Eloy Duran
- Milestone set to 2.3.6
-
Repository January 8th, 2010 @ 11:24 PM
- State changed from new to resolved
(from [f2aacd51405724cdf7cfd36a439c9dbfce16973a]) Rollback the transaction when one of the autosave associations fails to save. [#3391 state:resolved] http://github.com/rails/rails/commit/f2aacd51405724cdf7cfd36a439c9d...
-
Repository January 8th, 2010 @ 11:28 PM
(from [c9a3929a75ca01d5a637cf35b837c6fd8d6eb67d]) Rollback the transaction when one of the autosave associations fails to save. [#3391 state:resolved] http://github.com/rails/rails/commit/c9a3929a75ca01d5a637cf35b837c6...
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>
People watching this ticket
Referenced by
- 3391 nested attributes vs before_save (from [f2aacd51405724cdf7cfd36a439c9dbfce16973a]) Rollbac...
- 3391 nested attributes vs before_save (from [c9a3929a75ca01d5a637cf35b837c6fd8d6eb67d]) Rollbac...