【发布时间】:2014-11-07 05:02:45
【问题描述】:
我正在使用 facebook api 从 fb 获取用户。
我想将用户存储在我的模型User
我正在使用has many through 关系来存储用户
我在user 模型中的用户模型关系。
has_many :friends, :through => :user_friends, :class_name => "User", :foreign_key => "friend_id"
User friends模型中间表获取用户好友。
belongs_to :user
belongs_to :user, :foreign_key => "friend_id"
用户朋友有user_id 和friend_id 列,我在迁移中添加了这些列。
在用户对象上使用 .friends 时出现错误。
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :user_friends in model User
有人可以帮忙吗? 提前致谢。
【问题讨论】:
-
用户和好友之间是否存在多对多关系?
-
@RichaSinha :是的,就像我们在社交网络中一样。
标签: ruby-on-rails associations has-many model-associations