0

这按预期工作:

[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
4

1 回答 1

0

我相信这是因为Node.new创建了一个具有空数组的节点对象的实例,而Node.create实际上是持久化到数据库的新节点实例的表示(可能会跳过具有空数组的字段)

于 2013-11-12T23:52:27.570 回答