1
class Parent
include Mongoid::Document
embeds_many :children
field :title
end
class Child
include Mongoid::Document
embedded_in :parent
field :name
end
Rails的控制檯Mongoid:顯示與embeded_in對象整個MongoDB的對象在Rails的控制檯
parent = Parent.new(:title => "Hello World")
parent.children << Child.new(:name => "Pedro")
parent
#=> #<Parent _id: 4e2330286254cc0e7d000007, _type: nil, title: "Hellow World">
所以,我怎麼能檢查在Rails的控制檯整個對象,直到孩子在我的parent
包埋就像我能做到這一點在mogodb控制檯
{
"_id" : ObjectId("4e2330286254cc0e7d000007"),
"title": "Hello World",
"children" : [
{
"_id" : ObjectId("4d3ed089fb60ab534684b7e0"),
"name" : "Pedro"
}
]
}
就是這樣,謝謝:) – fl00r