fix
This commit is contained in:
parent
83f328d8ff
commit
73af54b952
|
@ -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,18 +44,26 @@ 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;
|
||||
}
|
Loading…
Reference in New Issue