orm
orm copied to clipboard
Missing type casting call for primary key
PHP Version: 8.0 Cycle ORM: 1.5.0
If you use the UUID as the primary key, then when fetching related records, the ORM crashes with an error:
[TypeError]
array_key_exists(): Argument #1 ($key) must be a valid offset type.
https://github.com/cycle/orm/blob/master/src/Parser/AbstractNode.php#L341
How to reproduce:
- Follow this guide https://cycle-orm.dev/docs/advanced-column-wrappers
- Follow this guide https://cycle-orm.dev/docs/advanced-uuid (but don't forget to replace Ramsey UUID with a typecasted object from p.1 in
nextPrimaryKey
).
Possible fix:
protected function mountArray(string $container, string $key, $criteria, array &$data): void
{
$criteria = (string) $criteria; // fix
if (!array_key_exists($criteria, $this->references[$key])) {
throw new ParserException("Undefined reference `{$key}`.`{$criteria}`");
}
foreach ($this->references[$key][$criteria] as &$subset) {
if (!in_array($data, $subset[$container], true)) {
$subset[$container][] = &$data;
}
unset($subset);
continue;
}
}
It is correct fix. Would you like to create a PR?
PR merged but still neet to add test case
Outdated