示例#1
0
 /**
  * Hydrates a node by querying the database for it
  * and updating it's reserved attributes from the
  * queried record.
  *
  * @param  Cartalyst\NestedSets\Nodes\NodeInterface  $node
  * @return void
  */
 public function hydrateNode(NodeInterface $node)
 {
     $table = $this->getTable();
     $attributes = $this->getReservedAttributeNames();
     $keyName = $this->baseNode->getKeyName();
     $result = $this->connection->table("{$table}")->where($keyName, '=', $key = $node->getAttribute($keyName))->first(array_values($attributes));
     if ($result === null) {
         throw new \RuntimeException("Attempting to hydrate non-existent node [{$key}].");
     }
     // We only want to update the attributes which
     // affect nested sets.
     $attributes = array_intersect_key((array) $result, array_flip($attributes));
     foreach ($attributes as $key => $value) {
         $node->setAttribute($key, $value);
     }
 }