This commit is contained in:
Michal Sieciechowicz 2021-09-29 17:19:48 +02:00
parent 83f328d8ff
commit 73af54b952
1 changed files with 14 additions and 9 deletions

View File

@ -7,7 +7,7 @@ use Fufle\ORM\Database\ConnectionManager;
abstract class Model {
protected static string $primaryKey = 'id';
protected static ?string $table = null;
private static ?IQuery $query = null;
protected static ?IQuery $query = null;
protected static array $fields = [];
@ -15,7 +15,7 @@ abstract class Model {
$array = [];
$fields = static::$fields;
foreach($fields as $field) {
if ($this->{$field} ?? null !== null) {
if (isset($this->{$field})) {
$array[$field] = $this->{$field};
}
}
@ -23,10 +23,7 @@ abstract class Model {
}
protected static function QueryModel() {
if (true || (self::$query === null && self::class !== static::class)) {
self::$query = static::SetQueryModel();
}
return self::$query;
return static::SetQueryModel();
}
public static function GetTableName() {
@ -47,17 +44,25 @@ abstract class Model {
}
protected static function Query(string $sql, array|object $params = []) {
return ConnectionManager::Query(
$result = ConnectionManager::Query(
$sql,
$params,
get_called_class());
if (!$result) {
return null;
}
return $result;
}
protected static function QueryAll(string $sql, array|object $params = []) {
return ConnectionManager::QueryAll(
$result = ConnectionManager::QueryAll(
$sql,
$params,
get_called_class());
if (!$result) {
return [];
}
return $result;
}
abstract public static function SetQueryModel(): IQuery;