我想将博客及其标签存储为单独的文档。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