Skip to content

Instantly share code, notes, and snippets.

@istan
Created July 9, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save istan/3077218 to your computer and use it in GitHub Desktop.
Save istan/3077218 to your computer and use it in GitHub Desktop.
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