Example #1
0
 /**
  * 设置当前节点的父级
  *
  * @param  static|int|array $target 实例或者主键ID
  * @param  string           $column 保存父级ID的字段
  * @return static
  */
 protected function parentFrom($target, $column = null)
 {
     if (!$target instanceof $this) {
         $target = new self($target);
     }
     if ($column === null) {
         $column = $target->primaryKey();
     }
     if ($target->loaded()) {
         $this->{$this->_parentColumn} = $target->{$column};
     } else {
         $this->{$this->_parentColumn} = null;
     }
     return $target;
 }