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
ModelInterface
ID is now typed asmixed
. This also affects theModelInterface->getId(): mixed
andModelInterface->setId(mixed $id): static
methods. ModelInterface->setId(mixed $id): static
now returnsstatic
instead ofvoid
.ModelInterface::get(): ?static
now returnsnull
if the model is not found instead offalse
.ModelInterface::getIdField()
andModelInterface::getCacheTime()
are now static.ModelCollection
offset functions (fromArrayAccess
) now havemixed
types for all arguments to follow theArrayAccess
interface.ModelRegistry->get(): ?ModelInterface
now returnsnull
if 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
Query
classes now have proper typing for their arguments and return types. GettableInterface->get(string $modelClass, mixed $id, ?ModelInterface $model = null): ?ModelInterface
only optionally applies data to a given model, usually it creates a new model usingModelInterface::getModelFromData(array $rawData): ?static
It also returnsnull
if the model is not found instead offalse
.
- The
ModelRegistry->get(string $className, string $id): ?ModelInterface
now 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): mixed
function.
ModelCollection
and its children now have generic type hinting in phpdoc allowing for type hinting the model type in the collection.GenericModel
now has the ability to define differentGenericModel::$variants
which are child classes of a basic model to separate different subtypes of a model. Each variant can differentGenericModel::$filters
which 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
CountField
andGenericModel::count()
for easier count queries. - Added
SumField
andAverageField
. - Added
GenericModel::reload(): static
to reload the model from the database.
- Removed
SimpleModel
. - Removed magic getter from
QueryResult
.