public function save(EntityInterface $entity, array $data = [])
    {
        $this->entity = $entity;
        $query = $this->getUpdateQuery();
        $data = $this->getData();
        $save = $this->triggerBeforeSave($query, $entity, $data);

        $query->set($save->params)
            ->execute();
        $lastId = $query->getAdapter()->getLastInsertId();
        if ($lastId) {
            $entity->setId($lastId);
        }

        $this->triggerAfterSave($save, $entity);

        $this->registerEntity($entity);
        return $this;
    }