开发者

Mongoid: show entire mongodb object with embeded_in objects in Rails console

class Parent
  include Mongoid::Document
  embeds_many :children
  field :title
end

class Child
  include Mongoid::Document
  embedded_in :parent
  field :name
end

Rails console

parent = Parent.new(:title => "Hello World")
parent.children << Child.new(:name => "Pedro")
parent
#=> #<Parent _id: 4e2330开发者_运维问答286254cc0e7d000007, _type: nil, title: "Hellow World">

So how can I inspect entire object in Rails console, till children are embeded in my parent like I can do it in mogodb console

{
  "_id" : ObjectId("4e2330286254cc0e7d000007"),
  "title": "Hello World",
  "children" : [
    {
      "_id" : ObjectId("4d3ed089fb60ab534684b7e0"),
      "name" : "Pedro"
    }
  ]
}


You can try to inspect the attributes of your Mongoid object like so:

parent.attributes.inspect
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜