Has_many :through and association callbacks: Working?

Hi,

does anybody know if the association callbacks
like :after_add, :before_remove should work together with the :through
option of a has_many association?

For me it actually seems not to work. And I don’t know if it is a
problem of mine or generally not a feature. The Rails API docs just
state that the association callbacks work with has_many.

Any ideas?

Feurio

On May 30, 10:19 am, Feurio [email protected] wrote:

Hi,

does anybody know if the association callbacks
like :after_add, :before_remove should work together with the :through
option of a has_many association?

If you look at the code:

if options[:through]
collection_reader_method(reflection, HasManyThroughAssociation)
collection_accessor_methods(reflection, HasManyThroughAssociation,
false)
else
add_multiple_associated_save_callbacks(reflection.name)
add_association_callbacks(reflection.name, reflection.options)
collection_accessor_methods(reflection, HasManyAssociation)
end

So it would appear not. Has many through is a bit odd since it’s
actually an association proxy rather than an association collection,
so some things are a bit odd. Luckily in edge rails (soon to be 2.1)
Pratik tidied all that up and so I would imagine the callbacks would
work.

Fred