- Added partial support for Index as primary keys

This commit is contained in:
Dave Mc Nicoll committed 2025-03-11 19:36:00 +00:00
1 parent e0ec140661
commit bfddf84564
4 files changed
+24 -9

No files matched your search

+19 -5
View File
@@ -144,13 +144,27 @@ trait EntityTrait {
return false;
}
if ( null === $pkField = $this->resolveEntity()->getPrimaryKeyField($this) ) {
throw new Exception\EntityPrimaryKeyUnknown(sprintf("Entity %s has no field containing attributes 'primary_key'", static::class));
if ( null === $pkField = $this->resolveEntity()->getPrimaryKeyField() ) {
if ( null !== $compoundKeyFields = $this->resolveEntity()->getCompoundKeyFields() ) {
$loaded = false;
foreach ($compoundKeyFields->column as $column) {
$field = $this->resolveEntity()->field($column);
if (! $field->allowsNull() ) {
$loaded |= isset($this->{$field->name});
}
}
return $loaded;
};
}
else {
$key = key($pkField);
return isset($this->$key);
}
$key = key($pkField);
return isset($this->$key);
throw new Exception\EntityPrimaryKeyUnknown(sprintf("Entity %s has no field containing attributes 'primary_key'", static::class));
}
#[Ignore]