# Modifying an association during inheritance

**URL:** <https://www.ruby-forum.com/t/modifying-an-association-during-inheritance/190201>\
**Category:** Rails\
**Created:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/modifying-an-association-during-inheritance/190201 "2010-06-17T16:22:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kampers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/54ee81/32.png) [@kampers](https://www.ruby-forum.com/u/kampers)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/modifying-an-association-during-inheritance/190201/1 "2010-06-17T16:22:18Z")

</div>

I have a Team class that inherits from a Group class. Both Team and  
Groups have memberships through the same association. However, I need  
to run a method after a Team memberships is added but not a Group. I  
currently have something like this:

class Group \< ActiveRecord::Base  
has\_many :memberships,  
:class\_name =\> ‘Connection’,  
:foreign\_key =\> ‘connectable\_id’,  
:as =\> :connectable,  
:dependent =\> :destroy  
end

class Team \< Group  
has\_many :memberships,  
:class\_name =\> ‘Connection’,  
:foreign\_key =\> ‘connectable\_id’,  
:as =\> :connectable,  
:dependent =\> :destroy,  
:after\_add =\> :add\_company\_membership

private  
def membership\_check(membership)  
end  
end

Is there some way to modify the inherited association in Team so that  
I don’t have to redefine the entire thing but rather just add  
the :after\_add hook it?

Any help would be appreciated.
