This commit is contained in:
Michał Sieciechowicz 2021-02-28 01:01:37 +01:00
parent 7e7e0dfe6c
commit be4eef7cac
3 changed files with 7 additions and 6 deletions

View File

@ -15,7 +15,7 @@ class JobModel extends BaseModel {
echo "init "; echo "init ";
if (static::$query === null) { if (static::$query === null) {
echo "query "; echo "query ";
static::$query = new JobQuery($this); static::$query = new JobQuery(self::class);
} }
} }
public static function GetLast10() { public static function GetLast10() {

View File

@ -9,11 +9,11 @@ abstract class Model {
protected static ?string $table = null; protected static ?string $table = null;
protected static ?IQuery $query = null; protected static ?IQuery $query = null;
public function getTableName() { public static function getTableName() {
return static::$table; return static::$table;
} }
public function getPrimaryKey() { public static function getPrimaryKey() {
return static::$primaryKey; return static::$primaryKey;
} }

View File

@ -4,9 +4,10 @@ namespace Fufle\ORM;
class Query { class Query {
private string $table; private string $table;
private string $primaryKey; private string $primaryKey;
public function __construct(Model $model) { public function __construct(string $model) {
$this->table = $model->getTableName(); ,//$model = new $class();
$this->primaryKey = $model->getPrimaryKey(); $this->table = $model::getTableName();
$this->primaryKey = $model::getPrimaryKey();
} }
public function Get(): string { public function Get(): string {
return 'SELECT * FROM '.$this->table.' WHERE '.$this->primaryKey.' = ?'; return 'SELECT * FROM '.$this->table.' WHERE '.$this->primaryKey.' = ?';