# Callbacks when deleting self-referenced has\_many?

**URL:** <https://www.ruby-forum.com/t/callbacks-when-deleting-self-referenced-has-many/185569>\
**Category:** Ruby\
**Created:** [March 22, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/callbacks-when-deleting-self-referenced-has-many/185569 "2010-03-22T22:36:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [March 22, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/callbacks-when-deleting-self-referenced-has-many/185569/1 "2010-03-22T22:36:47Z")

</div>

Hi

I’ve come across a behavior which doesn’t seem to be consistent. Let’s  
assume the following models:

class Client \<\< ActiveRecord::Base  
has\_many :resale\_clients, :foreign\_key =\> ‘reseller\_id’  
end

class ResaleClient \<\< Client  
belongs\_to :client, :foreign\_key =\> ‘reseller\_id’  
after\_save :ack  
def ack  
puts “triggered”  
end  
end

Now in the console (assuming two Client records exist in the db):

> > c = Client.first  
> > r = ResaleClient.find(2)  
> > c.resale\_clients \<\< r # outputs “triggered”  
> > c.resale\_clients.delete® # does not output “triggered”

Any idea what I’m doing wrong here?

Many thanks!!

---

<div class="post-metadata">

**Author:** ![enduro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@enduro](https://www.ruby-forum.com/u/enduro)\
**Post date:** [March 23, 2010, 10:29am UTC](https://www.ruby-forum.com/t/callbacks-when-deleting-self-referenced-has-many/185569/2 "2010-03-23T10:29:53Z")

</div>

Figured it out, I should be using the association callbacks. For some  
odd reason, I’ve never needed them up until now:

> **[Active Record Associations — Ruby on Rails Guides](https://guides.rubyonrails.org/association_basics.html#association-callbacks)**
>
> Active Record AssociationsThis guide covers the association features of Active Record.After reading this guide, you will know: How to declare associations between Active Record models. How to understand the various types of Active Record...
