Skip to content

Instantly share code, notes, and snippets.

@YuriFontella
Created February 24, 2016 17:20
Show Gist options
  • Save YuriFontella/d964dfc8c78ff0aefa81 to your computer and use it in GitHub Desktop.
Save YuriFontella/d964dfc8c78ff0aefa81 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_many :activities
# Ativamente... os que eu sigo
has_many :active_relationships, class_name: 'Relationship', foreign_key: 'follower_id', dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
end
class Activity < ActiveRecord::Base
belongs_to :subject, polymorphic: true
belongs_to :user
end
class Relationship < ActiveRecord::Base
belongs_to :follower, class_name: 'User'
belongs_to :followed, class_name: 'User'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment