# Has\_many :through and association callbacks: Working?

**URL:** <https://www.ruby-forum.com/t/has-many-through-and-association-callbacks-working/139043>\
**Category:** Rails\
**Created:** [May 30, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/has-many-through-and-association-callbacks-working/139043 "2008-05-30T12:10:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feurio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3bc359/32.png) [@Feurio](https://www.ruby-forum.com/u/Feurio)\
**Post date:** [May 30, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/has-many-through-and-association-callbacks-working/139043/1 "2008-05-30T12:10:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Feurio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/3bc359/32.png) [@Feurio](https://www.ruby-forum.com/u/Feurio)\
**Post date:** [May 30, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/has-many-through-and-association-callbacks-working/139043/2 "2008-05-30T18:17:05Z")

</div>

On May 30, 10:19 am, Feurio [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
