Created
July 9, 2012 15:39
-
-
Save istan/3077218 to your computer and use it in GitHub Desktop.
This file contains 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
class Regularship < ActiveRecord::Base | |
... | |
belongs_to :user | |
belongs_to :regulee, :class_name => "User", :counter_cache => true | |
... | |
end | |
class User < ActiveRecord::Base | |
... | |
# assocs for regular/regulee self-referential relationship FYI: referred to as "following" in app UI | |
has_many :regularships, :dependent => :destroy | |
has_many :regulees, :through => :regularships | |
has_many :reguleeships, :class_name => "Regularship", :foreign_key => "regulee_id", :dependent => :destroy | |
has_many :regulars, :through => :reguleeships, :source => :user | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment