This project is archived and is in readonly mode.

#2664 ✓stale
Nathaniel Bibler

Update the documentation for association callbacks

Reported by Nathaniel Bibler | May 17th, 2009 @ 05:54 PM | in 3.x

This is a follow-up ticket to discontinue hijacking ticket #2100. See comments starting here.

The documentation around the association callbacks (@after_add@, after_remove) is insufficient. It fails to highlight the that objects may be returned to those callback methods which are invalid and/or non-persisted. In the current implementation, you must do something like the following to ensure that you're working with an object that is actually created and persisted:

class Blog
  has_many posts, :after_add => :do_something
  def do_something(post)
    post.profit! unless post.new_record?
  end
end

This is highly unexpected behavior for something described as @after_add@, especially when if you refresh the parent object, the invalid child is non-existent.

I'll attempt a documentation patch to this thread in the coming days.

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>

Referenced by

Pages