From a3c38a27c70c71b521f65370ec87c34d10eaa3ac Mon Sep 17 00:00:00 2001 From: Michal Sieciechowicz Date: Mon, 1 Mar 2021 16:06:02 +0100 Subject: [PATCH] fixes --- app/Model/Job.php | 17 +++++++---------- app/Query/IJobQuery.php | 2 +- app/Query/JobQuery.php | 4 ++-- composer.json | 5 +++-- src/Fufle/ORM/Model.php | 33 +++++++++++++++++++-------------- src/Fufle/ORM/Query.php | 6 ++++-- tests/ModelTests.php | 12 ++++++------ 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/app/Model/Job.php b/app/Model/Job.php index 911d4b7..391ffc3 100644 --- a/app/Model/Job.php +++ b/app/Model/Job.php @@ -1,22 +1,19 @@ GetLast10()); + return self::QueryAll(self::QueryModel()->GetLast10()); } } \ No newline at end of file diff --git a/app/Query/IJobQuery.php b/app/Query/IJobQuery.php index ea0fb0b..6b44286 100644 --- a/app/Query/IJobQuery.php +++ b/app/Query/IJobQuery.php @@ -1,6 +1,6 @@ Get(), + static::QueryModel()->Get(), [$id]); } - + protected static function Query(string $sql, array|object $params = []) { - self::Check(); return ConnectionManager::Query( $sql, $params, get_called_class()); } - + protected static function QueryAll(string $sql, array|object $params = []) { - self::Check(); return ConnectionManager::QueryAll( $sql, $params, @@ -46,6 +53,4 @@ abstract class Model { } static::Initialize(); } - - abstract public static function Initialize(); } \ No newline at end of file diff --git a/src/Fufle/ORM/Query.php b/src/Fufle/ORM/Query.php index 2052a56..a920ebb 100644 --- a/src/Fufle/ORM/Query.php +++ b/src/Fufle/ORM/Query.php @@ -4,10 +4,12 @@ namespace Fufle\ORM; class Query { private string $table; private string $primaryKey; + public function __construct(string $model) { - $this->table = $model::getTableName(); - $this->primaryKey = $model::getPrimaryKey(); + $this->table = $model::GetTableName(); + $this->primaryKey = $model::GetPrimaryKey(); } + public function Get(): string { return 'SELECT * FROM '.$this->table.' WHERE '.$this->primaryKey.' = ?'; } diff --git a/tests/ModelTests.php b/tests/ModelTests.php index 7510169..962e72a 100644 --- a/tests/ModelTests.php +++ b/tests/ModelTests.php @@ -1,19 +1,19 @@