1
我有三個型號:如何在沒有引用的情況下在MongoDb中存儲ObjectID?
class User
include Mongoid::Document
field :name, :type => String
has_many :comments
embeds_many :posts
end
class Post
include Mongoid::Document
field :title, :type => String
field :body, :type => String
embeds_many :comments
belongs_to :user
end
class Comment
include Mongoid::Document
field :text, :type => String
belongs_to :user
embedded_in :post
end
而且我有這樣的錯誤:
Referencing a(n) Comment document from the User document via a relational association is not allowed since the Comment is embedded.
好了,這就是正確的。但我如何儲存,誰寫了評論?
ty!這比我想象的要容易:) – enRai