public function delete()
{
if (!isset($this->data[static::PRIMARY_KEY_NAME])) {
return $this;
}
$this->db->beginTransaction();
$this->db->prepare("DELETE FROM `" . static::TABLE_NAME . "` WHERE `" . static::PRIMARY_KEY_NAME . "` = ?")->execute([$this->data[static::PRIMARY_KEY_NAME]]);
try {
$this->afterDelete();
} catch (\Exception $e) {
if ($this->db->inTransaction()) {
$this->db->rollBack();
}
throw $e;
}
if (!$this->db->inTransaction()) {
throw new Exception\LogicException('Transaction was commited before the time.');
}
$this->db->commit();
unset($this->data[static::PRIMARY_KEY_NAME]);
return $this;
}