1
是否可以禁用嵌入式文檔的_id?MongoMapper禁用嵌入式ID
例如,如果父母擁有嵌入的子文檔。如果我不打算從其他地方引用孩子,那麼讓孩子擁有一個ID似乎毫無意義。
class Parent
include MongoMapper::Document
one :child
key :name
end
class Child
include MongoMapper::EmbeddedDocument
key :name
end
parent = Parent.new(:name => 'parent',
:child => Child.new(:name => 'child'))
puts parent.to_json
{"id":"4ebeddde51d9e56dcb000006","name":"parent",
"child":{
"id":"4ebeddde51d9e56dcb000005",
"name":"child"}}