Rails 请问 self-join 的问题。实现 twitter 的 follower 和关注

gazeldx · December 19, 2011 · Last by suupic replied at February 04, 2012 · 3835 hits

用户表 users 我设计了一个关联表 follows

 create_table "follows", :id => false, :force => true do |t|
    t.integer  "me"
    t.integer  "you"
    t.datetime "created_at"
end

请问“这里”怎么写?

class User < ActiveRecord::Base
 #这里
end
class Follow < ActiveRecord::Base
 #这里 
end
belongs_to :xxx
has_many :xxx

我用 mongoid 的写法

has_and_belongs_to_many :following, 
                        :class_name => 'User', 
                        :inverse_of => :followers
has_and_belongs_to_many :followers, 
                        :class_name => 'User', 
                        :inverse_of => :following
You need to Sign in before reply, if you don't have an account, please Sign up first.