考虑以下 Mongoid 模型
class Doc
include Mongoid::Document
field :name, type: String
embeds_many :images
embeds_many :videos
end
class Image
include Mongoid::Document
field :url, type: String
field :caption, type: String
embedded_in :Doc
end
class Video
include Mongoid::Document
field :url, type: String
field :caption, type: String
embedded_in :Doc
end
与此模型相比
class Doc
include Mongoid::Document
field :name, type: String
embeds_many :images
embeds_many :videos
end
class Image
include Mongoid::Document
embeds_many :urls
embeds_many :captions
embedded_in :Doc
end
class Video
include Mongoid::Document
embeds_many :urls
embeds_many :captions
embedded_in :Doc
end
class Url
include Mongoid::Document
embedded_in :image
embedded_in :video
field :url, type: String
end
class Caption
include Mongoid::Document
embedded_in :image
embedded_in :video
field :caption, type: String
end
每个模型比另一个模型有什么好处?
为了简洁起见,我应该选择第一个,还是应该将其原子化到 url.url 点,以便以后对查询有更多控制权?