Fix issues with missing classes when being tested in Github Actions
Some checks failed
CI / test (8.2) (push) Has been cancelled
CI / test (8.3) (push) Has been cancelled
CI / test (8.4) (push) Has been cancelled

This commit is contained in:
Funky Waddle 2026-02-08 02:48:39 -06:00
parent 3e75c15df0
commit 61cefca113
4 changed files with 34 additions and 34 deletions

View file

@ -30,6 +30,7 @@ jobs:
- name: Initialize Pairity - name: Initialize Pairity
run: | run: |
bin/pairity init bin/pairity init
bin/pairity make:model tests/Fixtures/schema
- name: Run tests - name: Run tests
run: | run: |

View file

@ -231,9 +231,10 @@ abstract class BaseDAO
* Insert a new record. * Insert a new record.
* *
* @param array<string, mixed> $data * @param array<string, mixed> $data
* @param \Pairity\DTO\BaseDTO|null $dto
* @return bool * @return bool
*/ */
protected function insert(array $data): bool protected function insert(array $data, ?\Pairity\DTO\BaseDTO $dto = null): bool
{ {
if ($this->getOption('tenancy', false)) { if ($this->getOption('tenancy', false)) {
$tenantColumn = \Pairity\Database\Query\Scopes\TenantScope::getTenantColumn(); $tenantColumn = \Pairity\Database\Query\Scopes\TenantScope::getTenantColumn();

View file

@ -86,8 +86,12 @@ class {{class}} extends BaseDAO
* @param {{dto_class}} $dto * @param {{dto_class}} $dto
* @return bool * @return bool
*/ */
public function save({{dto_class}} $dto): bool public function save(\Pairity\DTO\BaseDTO $dto): bool
{ {
if (!$dto instanceof {{dto_class}}) {
return parent::save($dto);
}
if ($this->fireModelEvent('saving', $dto) === false) { if ($this->fireModelEvent('saving', $dto) === false) {
return false; return false;
} }
@ -96,9 +100,9 @@ class {{class}} extends BaseDAO
$primaryKeyValue = $data[$this->primaryKey] ?? null; $primaryKeyValue = $data[$this->primaryKey] ?? null;
if ($primaryKeyValue === null) { if ($primaryKeyValue === null) {
$result = $this->insert($dto); $result = $this->insert($data, $dto);
} else { } else {
$result = $this->update($dto); $result = $this->update($primaryKeyValue, $data, $dto);
} }
if ($result) { if ($result) {
@ -111,24 +115,19 @@ class {{class}} extends BaseDAO
/** /**
* Insert a new record. * Insert a new record.
* *
* @param {{dto_class}} $dto * @param array $data
* @param \Pairity\DTO\BaseDTO|null $dto
* @return bool * @return bool
*/ */
protected function insert({{dto_class}} $dto): bool protected function insert(array $data, ?\Pairity\DTO\BaseDTO $dto = null): bool
{ {
if ($this->fireModelEvent('creating', $dto) === false) { if ($dto && $this->fireModelEvent('creating', $dto) === false) {
return false; return false;
} }
$data = $dto->toArray(); $result = parent::insert($data);
$columns = implode(', ', array_keys($data));
$placeholders = implode(', ', array_fill(0, count($data), '?'));
$sql = "INSERT INTO {$this->table} ({$columns}) VALUES ({$placeholders})"; if ($result && $dto) {
$result = $this->getConnection()->execute($sql, array_values($data)) > 0;
if ($result) {
$this->fireModelEvent('created', $dto, false); $this->fireModelEvent('created', $dto, false);
} }
@ -138,32 +137,20 @@ class {{class}} extends BaseDAO
/** /**
* Update an existing record. * Update an existing record.
* *
* @param {{dto_class}} $dto * @param mixed $id
* @param array $data
* @param \Pairity\DTO\BaseDTO|null $dto
* @return bool * @return bool
*/ */
protected function update({{dto_class}} $dto): bool protected function update(mixed $id, array $data, ?\Pairity\DTO\BaseDTO $dto = null): bool
{ {
if ($this->fireModelEvent('updating', $dto) === false) { if ($dto && $this->fireModelEvent('updating', $dto) === false) {
return false; return false;
} }
$data = $dto->toArray(); $result = parent::update($id, $data, $dto);
$id = $data[$this->primaryKey] ?? null;
$sets = [];
$values = [];
foreach ($data as $column => $value) { if ($result && $dto) {
if ($column === $this->primaryKey) continue;
$sets[] = "{$column} = ?";
$values[] = $value;
}
$values[] = $id;
$sql = "UPDATE {$this->table} SET " . implode(', ', $sets) . " WHERE {$this->primaryKey} = ?";
$result = $this->getConnection()->execute($sql, $values) > 0;
if ($result) {
$this->fireModelEvent('updated', $dto, false); $this->fireModelEvent('updated', $dto, false);
} }

View file

@ -0,0 +1,11 @@
columns:
id:
type: bigInteger
primary: true
email:
type: string
unique: true
relations:
posts:
type: hasMany
target: posts