私は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-schema は適していますか?