2011-07-17 23 views
1
class Parent 
    include Mongoid::Document 
    embeds_many :children 
    field :title 
end 

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

Rails的控制檯Mongoid:顯示與embeded_in對象整個MongoDB的對象在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" 
    } 
    ] 
} 

回答

5

你可以嘗試檢查你的Mongoid對象的屬性,像這樣:

parent.attributes.inspect 
+0

就是這樣,謝謝:) – fl00r