From be4eef7cacac9d2afd87414e5c1c7cd8f2a5df95 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 28 Feb 2021 01:01:37 +0100 Subject: [PATCH] static --- app/Model/JobModel.php | 2 +- src/Fufle/ORM/Model.php | 4 ++-- src/Fufle/ORM/Query.php | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Model/JobModel.php b/app/Model/JobModel.php index cda9dc8..ee026f6 100644 --- a/app/Model/JobModel.php +++ b/app/Model/JobModel.php @@ -15,7 +15,7 @@ class JobModel extends BaseModel { echo "init "; if (static::$query === null) { echo "query "; - static::$query = new JobQuery($this); + static::$query = new JobQuery(self::class); } } public static function GetLast10() { diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index 5b254dd..047ddbd 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -9,11 +9,11 @@ abstract class Model { protected static ?string $table = null; protected static ?IQuery $query = null; - public function getTableName() { + public static function getTableName() { return static::$table; } - public function getPrimaryKey() { + public static function getPrimaryKey() { return static::$primaryKey; } diff --git a/src/Fufle/ORM/Query.php b/src/Fufle/ORM/Query.php index 6a9720d..f360ee9 100644 --- a/src/Fufle/ORM/Query.php +++ b/src/Fufle/ORM/Query.php @@ -4,9 +4,10 @@ namespace Fufle\ORM; class Query { private string $table; private string $primaryKey; - public function __construct(Model $model) { - $this->table = $model->getTableName(); - $this->primaryKey = $model->getPrimaryKey(); + public function __construct(string $model) { + ,//$model = new $class(); + $this->table = $model::getTableName(); + $this->primaryKey = $model::getPrimaryKey(); } public function Get(): string { return 'SELECT * FROM '.$this->table.' WHERE '.$this->primaryKey.' = ?';