开发者

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

开发者 https://www.devze.com 2023-03-20 18:04 出处:网络
class Parent include Mongoid::Document embeds_many :children field :title end class Child include Mongoid::Document
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

精彩评论

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