There are many reasons before and after add callbacks will be useful on belongs_to associations. Here's one:
In my application, I have a set of associations that need to be maintained together. Specifically, I have versioned wiki pages, with comments. The comments belong to the wiki page itself, as well as to the particular version that was current when the comment was written. It looks like this in practice:
class Comment < ActiveRecord::Base
belongs_to :wiki_page, :after_add => :associate_with_current_version
belongs_to :wiki_page_version
def associate_with_current_version wiki_page
self.wiki_page_version = wiki_page.current_version
end
end
Ok, so now I'm rethinking my schema here, and might just go with a simpler association only with the wiki_page_version, on the grounds that caching the wiki_page_id on the table is premature optimization. But callbacks on belongs_to associations seem just as useful as those on any other association.
If there is demand for it, I can also add the before_remove and after_remove callbacks.
My patch includes tests.