ruby - Modifying an inherited Rails association -


I have a team class that gets from group class, both teams and groups are subscribed through a single association . However, I need to run a method because membership of a team is included but no group. I currently have something like this:

  class group & lt; ActiveRecord :: Base has has_many: membership, class_name = & gt; 'Connection' ,: foreign_key => 'Connectable_id' ,: as = & gt; : Connectable ,: Dependent = & gt; : Destroy the End Class Team & lt; Group has_many: membership, class_name = & gt; 'Connection' ,: foreign_key => 'Connectable_id' ,: as = & gt; : Connectable ,: Dependent = & gt; : Destroyed, after_add = & gt; : Membership_check Private def Membership Check and end  

Is there a way to modify the inherited association in the team so that I do not need to redefine the whole thing, Rather to add it:

Try it and let me know if it works, let me think Be sure your membership_check method is no longer private.

  class group & lt; ActiveRecord :: Base has has_many: membership, class_name = & gt; 'Connection' ,: foreign_key => 'Connectable_id' ,: as = & gt; : Connectable ,: Dependent = & gt; : Destroyed, after_add = & gt; Proc {| Gr, Dev | Gr.membership_check (dev) if gr.respond_to? : Membership_check} end-team team & lt; Group Diff Membership-Check (Subscription) End End  

P.S. I'm not sure what you should do in the subscription-check logic, but the developer added it looks like this.

PPS If you want to keep membership_check private, you can use gr.send (: membership_check, dev) to bypass visibility barrier but I do not know Why do you want


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -