Describe the bug
If Entity have getter:
/** * @return list<Tag> */publicfunctiongetTags(): ?array
{
return$this->attributes['tags'] ?? [];
}in PostModel:
publicfunctiontags(): Relation
{
return$this->belongsToMany(TagModel::class);
}The lazy loading request is not working. To work, you need to return null.
To Reproduce
Add getter for relation prop and set . Call $entity->tags
Expected behavior
An empty array is expected to be overwritten, not just null/undefined properties.
Screenshots
No.
Environment (please complete the following information):
- PHP: 8.4.13
- Server: cli
- Version dev-latest
- CodeIgniter: 4.6.3
Additional context
To fast fix:
trait HasLazyRelations
{
publicfunction__get(string$key)
{
$result = parent::__get($key);
if ($result === null || $result === []) {
$result = $this->handleRelation($key);
}
return$result;
}
//...
Describe the bug
If Entity have getter:
in PostModel:
The lazy loading request is not working. To work, you need to return
null.To Reproduce
Add getter for relation prop and set . Call
$entity->tagsExpected behavior
An empty array is expected to be overwritten, not just null/undefined properties.
Screenshots
No.
Environment (please complete the following information):
Additional context
To fast fix: