Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Update the documentation for association callbacks

#2664

This is a follow-up ticket to discontinue hijacking ticket #2100 Change behaviour of association's after_add callback. 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.

Reported by Nathaniel Bibler · May 17th, 2009 @ 05:54 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  2. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:16 AM

  3. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:53 PM

  4. Jeff Kreeftmeijer