我想將博客及其標籤存儲爲單獨的文檔。Mongoid多對多問題
博客文章應該有tag_ids字段和標籤不應該有blog_posts_ids字段。
Mongoid提供了許多開箱即用的關係,但它需要多對多關係的文檔都有_ids字段。
class BlogPost
include Mongoid::Document
field :title
references_many :tags, :stored_as => :array, :inverse_of => :blog_posts
end
class Tag
include Mongoid::Document
field :name
# I DON'T WANT TO STORE BLOG_POSTS_IDS IN TAG DOCUMENT
references_many :blog_posts, :stored_as => :array, :inverse_of => :tags
end
誰不能用mongoid代碼。創建你自己的方法。 – shingara 2010-11-08 08:29:52