Cake\ElasticSearch\Type::delete PHP 메소드

delete() 공개 메소드

Deletes an entity and possibly related associations from the database based on the 'dependent' option used when defining the association. Triggers the Model.beforeDelete and Model.afterDelete events.
public delete ( Cake\Datasource\EntityInterface $entity, array $options = [] ) : boolean
$entity Cake\Datasource\EntityInterface The entity to remove.
$options array The options for the delete.
리턴 boolean success
    public function delete(EntityInterface $entity, $options = [])
    {
        if (!$entity->has('id')) {
            $msg = 'Deleting requires an "id" value.';
            throw new InvalidArgumentException($msg);
        }
        $options += ['checkRules' => true];
        $options = new ArrayObject($options);
        $event = $this->dispatchEvent('Model.beforeDelete', ['entity' => $entity, 'options' => $options]);
        if ($event->isStopped()) {
            return $event->result;
        }
        if (!$this->checkRules($entity, RulesChecker::DELETE, $options)) {
            return false;
        }
        $data = $entity->toArray();
        unset($data['id']);
        $doc = new ElasticaDocument($entity->id, $data);
        $type = $this->connection()->getIndex()->getType($this->name());
        $result = $type->deleteDocument($doc);
        $this->dispatchEvent('Model.afterDelete', ['entity' => $entity, 'options' => $options]);
        return $result->isOk();
    }