This project is archived and is in readonly mode.

#4599 ✓resolved
Daniele Orlandi

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

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>

Tags

Pages