This project is archived and is in readonly mode.

#3353 ✓committed
qoobaa

accepts_nested_attributes, validates_presence_of - saves associated model

Reported by qoobaa | October 8th, 2009 @ 03:32 PM | in 2.3.10

We've got two model classes:

class User < ActiveRecord::Base
  has_many :posts
  after_save { puts "after_save" }
end

class Post < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :user
  accepts_nested_attributes_for :user
end
>> User.create!
after_save
>> Post.create!(:user => User.first)
after_save
=> #<Post id: 1, user_id: 1, created_at: "2009-10-08 14:02:04", updated_at: "2009-10-08 14:02:04">
>> Post.first.touch
after_save
=> true

We're executing after_save callback by touching associated post model. It's totally unexpected behavior. It's quite similar to #2578, but the patch doesn't solve the problem.

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

Referenced by

Pages