Created
March 8, 2012 12:23
-
-
Save ekampf/2000771 to your computer and use it in GitHub Desktop.
Basically, the has_many association controls how the "join model" (Subscription) is created and the has_many_through association controls how the :through model is created. So instead of having one has_many :subscriptions I split it to two...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_many :subscriptions_members, | |
:class_name => "Subscription", | |
:conditions => {:kind => Subscription::SubscriptionKinds::MEMBER}, | |
:dependent => :destroy | |
has_many :subscriptions_followers, | |
:class_name => "Subscription", | |
:conditions => {:kind => Subscription::SubscriptionKinds::FOLLOWER}, | |
:dependent => :destroy | |
has_many :members, :through => :subscriptions_members, | |
:source => :user, :uniq => true | |
has_many :followers,:through => :subscriptions_followers, | |
:source => :user, :uniq => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!