ajout méthode find dans le model

This commit is contained in:
2023-11-04 09:43:58 +01:00
parent aa551c697b
commit 39eb008118
2 changed files with 37 additions and 1 deletions

View File

@@ -31,6 +31,11 @@ class Model
return $this;
}
public function getValues(): array
{
return $this->values;
}
public function getPk(): string
{
return $this->pk;
@@ -61,6 +66,19 @@ class Model
return $this;
}
public function find(mixed $key): bool
{
$res = false;
$qb = $this->newQueryBuilder();
$find = $qb->find($key);
if($find!==null)
{
$this->fillData($find->getValues());
$res = true;
}
return $res;
}
public function save(): bool
{
$ret = false;
@@ -122,4 +140,5 @@ class Model
return $table;
}
}

View File

@@ -35,6 +35,23 @@ test("insert row",function () {
expect($ret2)->toBe(true);
});
test("model find", function() {
$row = new Model();
$row->setTable("test");
$res = $row->find(1);
expect($res)->toBe(true);
expect($row->col1)->toBe("test");
$row->col1 = "test2";
$res = $row->save();
expect($res)->toBe(true);
$row->col1 = "test";
$res = $row->save();
expect($res)->toBe(true);
});
test("querybuilder", function() {
$qb = new QueryBuilder("test");
$row = $qb->find(1);