diff --git a/src/Model.php b/src/Model.php index c800bcf..f0ced76 100644 --- a/src/Model.php +++ b/src/Model.php @@ -66,16 +66,15 @@ class Model return $this; } - public function find(mixed $key): bool - { - $res = false; + public function find(mixed $key): mixed + { $qb = $this->newQueryBuilder(); $find = $qb->find($key); if ($find !== null) { $this->fillData($find->getValues()); - $res = true; + return $this; } - return $res; + return null; } public function save(): bool diff --git a/tests/DbTest.php b/tests/DbTest.php index 375e239..0d45035 100644 --- a/tests/DbTest.php +++ b/tests/DbTest.php @@ -40,9 +40,12 @@ test("model find", function() { $row->setTable("test"); $res = $row->find(1); - expect($res)->toBe(true); + expect($res->id)->toBe(1); expect($row->col1)->toBe("test"); + $res = $row->find(15); + expect($res)->toBe(null); + $row->col1 = "test2"; $res = $row->save(); expect($res)->toBe(true);