class Parent
include Mongoid::Document
embeds_many :children
field :title
end
class Child
include Mongoid::Document
embedded_in :parent
field :name
end
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"
}
]
}
答案 0 :(得分:6)
您可以尝试检查Mongoid对象的属性,如下所示:
parent.attributes.inspect