ajout méthode find dans le model
This commit is contained in:
@@ -31,6 +31,11 @@ class Model
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValues(): array
|
||||||
|
{
|
||||||
|
return $this->values;
|
||||||
|
}
|
||||||
|
|
||||||
public function getPk(): string
|
public function getPk(): string
|
||||||
{
|
{
|
||||||
return $this->pk;
|
return $this->pk;
|
||||||
@@ -61,6 +66,19 @@ class Model
|
|||||||
return $this;
|
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
|
public function save(): bool
|
||||||
{
|
{
|
||||||
$ret = false;
|
$ret = false;
|
||||||
@@ -122,4 +140,5 @@ class Model
|
|||||||
|
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,23 @@ test("insert row",function () {
|
|||||||
expect($ret2)->toBe(true);
|
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() {
|
test("querybuilder", function() {
|
||||||
$qb = new QueryBuilder("test");
|
$qb = new QueryBuilder("test");
|
||||||
$row = $qb->find(1);
|
$row = $qb->find(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user