fl0*_*00r 3 ruby ruby-on-rails mongodb mongoid ruby-on-rails-3
class Parent
include Mongoid::Document
embeds_many :children
field :title
end
class Child
include Mongoid::Document
embedded_in :parent
field :name
end
Run Code Online (Sandbox Code Playgroud)
Rails控制台
parent = Parent.new(:title => "Hello World")
parent.children << Child.new(:name => "Pedro")
parent
#=> #<Parent _id: 4e2330286254cc0e7d000007, _type: nil, title: "Hellow World">
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能在Rails控制台中检查整个对象,直到孩子们被嵌入我的parent样式中我可以在mogodb控制台中执行它
{
"_id" : ObjectId("4e2330286254cc0e7d000007"),
"title": "Hello World",
"children" : [
{
"_id" : ObjectId("4d3ed089fb60ab534684b7e0"),
"name" : "Pedro"
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1813 次 |
| 最近记录: |