diff --git a/src/Fufle/ORM/Model.php b/src/Fufle/ORM/Model.php index d7d1ea3..0bfb589 100644 --- a/src/Fufle/ORM/Model.php +++ b/src/Fufle/ORM/Model.php @@ -8,6 +8,7 @@ abstract class Model { protected static string $primaryKey = 'id'; protected static ?string $table = null; protected static ?IQuery $query = null; + private static array $queryModels = []; protected static array $fields = []; @@ -21,7 +22,7 @@ abstract class Model { } return $array; } - + public static function Instance(object $object): static { $obj = new static; $params = get_object_vars($object); @@ -32,7 +33,11 @@ abstract class Model { } protected static function QueryModel() { - return static::SetQueryModel(); + if (!isset(static::$queryModels[static::class])) + if (static::$query === null) { + static::$queryModels[static::class] = static::SetQueryModel(); + } + return static::$queryModels[static::class]; } public static function GetTableName() {