使用Mongo和Rails,我会建立像facebook这样的友谊系统: - 在建立友谊之前,使用必须接受友谊请求
我找到了很多代码来处理关系,但从未使用过关系的属性......
你是否有任何想法或线索如何做到这一点是“尊重”NoSQL概念
感谢您的帮助
答案 0 :(得分:11)
只需使用两个模型,如下所示:
class User
include Mongoid::Document
has_many :friendships
end
class Friendship
include Mongoid::Document
belongs_to :owner, :class_name => "User"
belongs_to :friend, :class_name => "User"
field :pending, :type => Boolean, :default => true
end
听起来不错吗?希望这有帮助!
答案 1 :(得分:6)
我必须输入我的用户模型:
has_many :friendships, :inverse_of => :owner
查看文档http://mongoid.org/en/mongoid/docs/relations.html#common
中的关联