1
如何使用Mongoid在另一個類中兩次(或多次)引用相同的類?如何在另一個班級中多次引用同一班級?
class User
include Mongoid::Document
field :email
references_many :messages, :stored_as => :array #all messages where the user acts as a sender
references_many :messages, :stored_as => :array #all messages where the user acts as a receiver
end
class Message
include Mongoid::Document
field :Text
references_one :user #this should be the sender
references_one :user #this should be the receiver
end
和唐忘記了:inverse_of – sandrew 2010-12-15 16:42:39
此解決方案在當前(2012)MongoID版本中不再適用 – Matthias 2012-05-10 22:47:40