Is it possible to put association callbacks in -extensions?

I have a case, where I would like a Log event to take place each time an association is added or removed. This is currently implemented like this:

has_many :levels,

after_add: :log_adding_event,

after_remove: :log_removing_event

def log_adding_event object

Log.create(object, “adding”)


def log_removing_event object

Log.create(object, “removing”)


The fact that the callbacks isn’t aware of the association they’r triggered by. This means, that I need two separate methods to differentiate between adding and removing objects.

I know that extending the association allows methods to know about all kinds of goodies about the proxy association, which brings me to my question: Is it possible to move callbacks inside an association extension?