Define and Implement delete

This commit is contained in:
2022-09-09 13:15:27 -04:00
parent 9834eb70a4
commit 3811e8224b
4 changed files with 12 additions and 0 deletions

View File

@ -61,4 +61,8 @@ abstract class Model implements ModelInterface
}
$this->isDirty();
}
public function delete(): void
{
$this->getFactory()->get(get_class($this))->delete($this);
}
}

View File

@ -100,6 +100,12 @@ abstract class Repository implements RepositoryInterface
}
return $model;
}
public function delete(Model $model): void
{
$query = $this->getQueryBuilder()->delete($this->getTable())->where(['id = ?']);
$this->getConnection()->execute($query, [$model->getId()]);
}
public function fetchById(int $id): Model
{
$query = $this->getQueryBuilder()

View File

@ -15,4 +15,5 @@ interface Model
public function isDirty(): bool;
public function save(): void;
public function edit(array $data): void;
public function delete(): void;
}

View File

@ -23,6 +23,7 @@ interface Repository
public function save(Model $model): void;
public function edit(Model $model, array $data): Model;
public function create(array $data): Model;
public function delete(Model $model): void;
public function fetchById(int $id): Model;
public function fetchAll(): array;
}