Mongoid:在Rails控制台中使用embeded_in对象显示整个mongodb对象

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)

Mat*_*att 6

您可以尝试检查Mongoid对象的属性,如下所示:

parent.attributes.inspect
Run Code Online (Sandbox Code Playgroud)