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 ";
if (static::$query === null) {
echo "query ";
static::$query = new JobQuery($this);
static::$query = new JobQuery(self::class);
}
}
public static function GetLast10() {

View File

@ -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;
}

View File

@ -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.' = ?';