The ModelInterface ID is now typed as mixed. Any model extending GenericModel
have to change the type of the $id property to mixed:
class MyModel extends GenericModel
{
public $id;
}has to be changed to
class MyModel extends GenericModel
{
public mixed $id;
}The magic getter function of QueryResult was removed. They have to be accessed using the correct
array key (usually [0]).
$queryResult = MyModel::select(["field" => "value"]);
$value = $queryResult->field;has to be changed to
$queryResult = MyModel::select(["field" => "value"]);
$value = $queryResult[0]?->field;Dynamic properties are deprecated since PHP 8.2. Unknown fields are now stored in BaseModel->$additionalFields
and have to be accessed using the new ModelInterface->getField(string $key): mixed function.
$queryResult = MyModel::select(fields: [(new \Aternos\Model\Query\SelectField("field"))->setAlias("alias")]);
$value = $queryResult[0]?->alias;has to be changed to
$queryResult = MyModel::select(fields: [(new \Aternos\Model\Query\SelectField("field"))->setAlias("alias")]);
$value = $queryResult[0]?->getField("alias");- Potentially breaking type changes/additions:
- The
ModelInterfaceID is now typed asmixed. This also affects theModelInterface->getId(): mixedandModelInterface->setId(mixed $id): staticmethods. ModelInterface->setId(mixed $id): staticnow returnsstaticinstead ofvoid.ModelInterface::get(): ?staticnow returnsnullif the model is not found instead offalse.ModelInterface::getIdField()andModelInterface::getCacheTime()are now static.ModelCollectionoffset functions (fromArrayAccess) now havemixedtypes for all arguments to follow theArrayAccessinterface.ModelRegistry->get(): ?ModelInterfacenow returnsnullif the model is not found instead offalse.BaseModel->__construct(mixed $id)now has the typed argumentmixed $id.GenericModel::select()andGenericModel::update()now have fully typed arguments.GenericModel->set()now has the return typeQueryResult.- All
Queryclasses now have proper typing for their arguments and return types. GettableInterface->get(string $modelClass, mixed $id, ?ModelInterface $model = null): ?ModelInterfaceonly optionally applies data to a given model, usually it creates a new model usingModelInterface::getModelFromData(array $rawData): ?staticIt also returnsnullif the model is not found instead offalse.
- The
ModelRegistry->get(string $className, string $id): ?ModelInterfacenow takes the class name as the first argument instead of the model name. This function is also generic and type hints the return type from the first argument.- Fields that aren't defined in the model are no longer set as dynamic properties. They
have to be retrieved using the new
ModelInterface->getField(string $key): mixedfunction.
ModelCollectionand its children now have generic type hinting in phpdoc allowing for type hinting the model type in the collection.GenericModelnow has the ability to define differentGenericModel::$variantswhich are child classes of a basic model to separate different subtypes of a model. Each variant can differentGenericModel::$filterswhich are key value pairs that identify the type. Direct calls to get and query functions will automatically filter the results to the correct variant. Calls to the shared parent model will return all variants but of the correct subtype.- Added
CountFieldandGenericModel::count()for easier count queries. - Added
SumFieldandAverageField. - Added
GenericModel::reload(): staticto reload the model from the database.
- Removed
SimpleModel. - Removed magic getter from
QueryResult.