Releases: aternosorg/php-model
Releases · aternosorg/php-model
v3.2.5
v3.2.4
What's Changed
- Add IN and NOT IN operators to TestTableEntry by @JulianVennen in #8
New Contributors
- @JulianVennen made their first contribution in #8
Full Changelog: v3.2.3...v3.2.4
v3.2.3
v3.2.2
v3.2.1
v3.2.0
v3.1.0
3.0.0
Main breaking changes
ModelInterface ID type
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;
}
QueryResult getter
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
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");
Changed
- Potentially breaking type changes/additions:
- The
ModelInterface
ID is now typed asmixed
. This also affects the
ModelInterface->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 newModelInterface->getField(string $key): mixed
function.
Added
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 different
GenericModel::$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
- Removed
SimpleModel
. - Removed magic getter from
QueryResult
.
v1.2.0
This release changes the minimum required PHP version to PHP 8.0.
What's Changed
- Added more return types for PHP 8.1 compatibility.
- Update license year and rename Aternos UG to Aternos GmbH by @pavog in #1
New Contributors
Full Changelog: v1.1.4...v1.2.0