/** * @param Entity $entity * @return bool */ function delete(Entity $entity) { if (!$entity->getPK()) { throw new \LogicException("Cannot delete entity: PK is empty"); } $sql = "DELETE FROM {$entity->getSourceName()} " . " WHERE {$entity->getPKName()} = :{$entity->getPKName()}"; $stmt = $this->db->prepare($sql); $result = $stmt->execute([$entity->getPKName() => $entity->getPK()]); if (!$result) { throw new \RuntimeException("DELETE entity: DB query failed (PK: {$entity->getPK()})"); } return (bool) $stmt->rowCount(); }
/** * @param Entity $entity * @return bool */ function delete(Entity $entity) { if (!$entity->getPK()) { throw new \LogicException("Cannot delete entity: PK is empty"); } return $this->getIndex($entity)->deleteById($entity->id); }