diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index 272edfd..4a0bdc2 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -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; } \ No newline at end of file