Skip to content

Instantly share code, notes, and snippets.

@bachue
Created September 28, 2013 03:35
Show Gist options
  • Save bachue/6738086 to your computer and use it in GitHub Desktop.
Save bachue/6738086 to your computer and use it in GitHub Desktop.
ActiveRecord 测试复杂的关系
class User < ActiveRecord::Base
has_and_belongs_to_many :followees, class_name: 'User', foreign_key: 'follower_id', association_foreign_key: 'follow_id', :join_table => 'follows'
has_and_belongs_to_many :followers, class_name: 'User', foreign_key: 'follow_id', association_foreign_key: 'follower_id', :join_table => 'follows'
has_many :followers_comments, through: :followers, :source => :comments
has_many :comments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment