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