la méthode find de l'objet retourne l'objet lui même
This commit is contained in:
@@ -66,16 +66,15 @@ class Model
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find(mixed $key): bool
|
public function find(mixed $key): mixed
|
||||||
{
|
{
|
||||||
$res = false;
|
|
||||||
$qb = $this->newQueryBuilder();
|
$qb = $this->newQueryBuilder();
|
||||||
$find = $qb->find($key);
|
$find = $qb->find($key);
|
||||||
if ($find !== null) {
|
if ($find !== null) {
|
||||||
$this->fillData($find->getValues());
|
$this->fillData($find->getValues());
|
||||||
$res = true;
|
return $this;
|
||||||
}
|
}
|
||||||
return $res;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(): bool
|
public function save(): bool
|
||||||
|
|||||||
@@ -40,9 +40,12 @@ test("model find", function() {
|
|||||||
$row->setTable("test");
|
$row->setTable("test");
|
||||||
|
|
||||||
$res = $row->find(1);
|
$res = $row->find(1);
|
||||||
expect($res)->toBe(true);
|
expect($res->id)->toBe(1);
|
||||||
expect($row->col1)->toBe("test");
|
expect($row->col1)->toBe("test");
|
||||||
|
|
||||||
|
$res = $row->find(15);
|
||||||
|
expect($res)->toBe(null);
|
||||||
|
|
||||||
$row->col1 = "test2";
|
$row->col1 = "test2";
|
||||||
$res = $row->save();
|
$res = $row->save();
|
||||||
expect($res)->toBe(true);
|
expect($res)->toBe(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user