我有 json-documents 和 ruby 类
product
json文档:
{
"taxon_id": "5281bbed3aa823f9439dc02d",
"name": "Mongoid in Action",
"seo":
{
"permalink": "mongoid-in-action",
"metadata":
{
"description": "Great programming book by smarter authors",
"keywords": ["mongoid", "book", "action"],
"title": "Programming book: Mongoid in Action"
}
}
}
taxon
json文档:
{
"_id": "5281bbed3aa823f9439dc02d",
"name": "Programming",
"seo":
{
"permalink": "programming",
"metadata":
{
"description": "Catalogue for programming books",
"keywords": ["programming", "coding", "hacking"],
"title": "Programming books"
}
}
}
documents/matadata.rb
文件:
class Documents::Metadata
include Mongoid::Document
field :description, type: String
field :title, type: String
field :keywords, type: Array, default: []
embedded_in :seo
end
documents/seo.rb
文件:
class Documents::Seo
include Mongoid::Document
field :permalink, type: String
embeds_one :metadata
embedded_in :product
embedded_in :taxon
accepts_nested_attributes_for :metadata
end
documents/product.rb
文件:
class Documents::Product
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
embeds_one :seo
belongs_to :taxon
accepts_nested_attributes_for :seo
end
documents/taxon.rb
文件:
class Documents::Taxon
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
embeds_one :seo
has_many :products
accepts_nested_attributes_for :seo
end
我有共同的 seo json-document 并希望在其他文档之间共享。是不是正确的划分?json 模式是否合适?