# Callback has\_many

**URL:** <https://www.ruby-forum.com/t/callback-has-many/135503>\
**Category:** Rails\
**Created:** [April 22, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/callback-has-many/135503 "2008-04-22T18:49:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![julien51](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/91b2a8/32.png) [@julien51](https://www.ruby-forum.com/u/julien51)\
**Post date:** [April 22, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/callback-has-many/135503/1 "2008-04-22T18:49:00Z")

</div>

Hi everyone,

I am implementing fragment caching in my application

I’ve got the following architecture :

A :has\_many Cs :through Bs

I’ve got a sweeper that observes B, in which I’ve got 2 methods :  
after\_create(B) and after\_delete(B), which expire a fragment of my  
cache.

In my main controller, I adding/removing Cs to As like this :

A \<\< C, and this actually calls back after\_create(B), as expected

and

A.Cs.delete© which doesn’t perform any call to after\_delete(B), even  
though, the B element is actually deleted!

Is this a normal behavior? If so, why is the call back only called when  
creating and not deleting? And is there a “smart” way to actually call  
by sweeper on delete?

Thanks for your help!
