This project is archived and is in readonly mode.
Validations on nested attributes fail on nil foreign key on object creation
Reported by Daniele Orlandi | May 15th, 2010 @ 12:50 AM
Hello,
class Tag
belongs_to :post
validates_presence_of :post
end
class Post
has_many :post_tags
accepts_nested_attribute_for :post_tags
end
On Post creation save fails because tag's post is not yet set to the new Post id.
In facts, if the validation is removed the save is successful and the post_id is correctly filled in.
Comments and changes to this ticket
-
Santiago Pastorino May 16th, 2010 @ 04:58 PM
- Tag set to bugmash
-
Subba July 16th, 2010 @ 08:17 PM
- Importance changed from to Low
Daniele try this it will fix above problem.
class Tag belongs_to :post,:inverse_of => :post_tags validates_presence_of :post end class Post has_many :post_tags, :inverse_of => :post accepts_nested_attribute_for :post_tags end
-
Subba July 16th, 2010 @ 08:17 PM
- Assigned user set to Neeraj Singh
-
Neeraj Singh July 19th, 2010 @ 01:26 AM
- State changed from new to resolved
Solution proposed by Subba works for me. Marking it as resolved. If it is still an issue then let's discuss.
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>