Наследование: extends AbstractCollectionAttribute, use trait Webiny\Component\Mongo\MongoTrait
Пример #1
0
 /**
  * Unlink given item (only removes the aggregation record) and remove it from current loaded values
  *
  * @param Many2ManyAttribute    $attribute
  * @param string|EntityAbstract $item
  *
  * @return bool
  */
 public function unlink(Many2ManyAttribute $attribute, $item)
 {
     // Convert instance to entity ID
     if ($this->isInstanceOf($item, '\\Webiny\\Component\\Entity\\EntityAbstract')) {
         $item = $item->getId()->getValue();
     }
     $sourceEntityId = $attribute->getParentEntity()->getId()->getValue();
     if ($this->isNull($sourceEntityId) || $this->isNull($item)) {
         return;
     }
     $firstClassName = $this->extractClassName($attribute->getParentEntity());
     $secondClassName = $this->extractClassName($attribute->getEntity());
     $query = $this->arr([$firstClassName => $sourceEntityId, $secondClassName => $item])->sortKey()->val();
     $res = Entity::getInstance()->getDatabase()->remove($attribute->getIntermediateCollection(), $query);
     return $res['n'] == 1;
 }