这可以按预期工作:
[1] consum » node = Node.new(name: "p")
=> #<Node:0x007ff032b941d0> {
:_id => "51e88c41c7e9680108000001",
:name => "p",
:parent_ids => [],
:repeated => false
}
[2] consum » node.children
=> []
这不是:
[3] consum » node = Node.create(name: "p")
=> #<Node:0x007ff03250a6c0> {
:_id => "51e88c4dc7e9680108000002",
:created_at => 2013-07-19 00:46:05 UTC,
:name => "p",
:parent_ids => [],
:repeated => false,
:updated_at => 2013-07-19 00:46:05 UTC
}
[4] consum » node.children
=> nil
答案 0 :(得分:0)
我相信这是因为Node.new
创建了一个具有空数组的节点对象的实例,而Node.create
是实际持久存储到数据库的新节点实例的表示(可能是跳过了带有空数组的字段)