I have a Team class that inherits from the Group class. Both teams and groups have membership in the same association. However, I need to run the method after adding membership to the Team, but not the 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 => :membership_check
private
def membership_check(membership)
end
end
Is there any way to change the inherited association in Team, so I don’t need to redefine the whole thing, but just add: after_add to intercept it?
Any help would be appreciated.
source
share