示例#1
0
 /**
  * Delete children relation from current model.
  *
  * @param {?array|AbstractModel|int|string} $children Target children to delete, or all children of omitted.
  * @param {?string} $collection Collection identifier of the relation, defaults to the model's collection name.
  */
 protected function deleteDescendants($collection = '%', $children = null)
 {
     if ($collection === null) {
         $collection = $this->collectionName();
     }
     if ($children === null) {
         return Relation::deleteDescendants($this->identity(), $collection);
     } else {
         if (!is_array($children)) {
             $children = (array) $children;
         }
         return array_reduce($children, function ($result, $child) use($collection) {
             if ($child instanceof AbstractModel) {
                 $child = $child->identity();
             }
             return $result && Relation::delete($this->identity(), $child, $collection);
         }, true);
     }
 }