- Added partial support for Index as primary keys
This commit is contained in:
parent
e0ec140661
commit
bfddf84564
@ -11,4 +11,4 @@ class Index {
|
||||
public IndexTypeEnum $type = IndexTypeEnum::Unique,
|
||||
public null|string $name = null,
|
||||
) {}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace Ulmus\Common;
|
||||
use Notes\Common\ReflectedClass;
|
||||
use Notes\Common\ReflectedProperty;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Ulmus\Attribute\Obj\Index;
|
||||
use Ulmus\Ulmus,
|
||||
Ulmus\Attribute\Obj\Table,
|
||||
Ulmus\Attribute\Obj\AdapterAttributeInterface,
|
||||
@ -214,9 +215,9 @@ class EntityResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCompoundKeyFields() : ? array
|
||||
public function getCompoundKeyFields() : ? Index
|
||||
{
|
||||
return null;
|
||||
return $this->getAttributeImplementing(Index::class);
|
||||
}
|
||||
|
||||
public function getUniqueFields() : ? array
|
||||
|
@ -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]
|
||||
|
@ -97,7 +97,7 @@ class Repository implements RepositoryInterface
|
||||
else {
|
||||
$pk = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField();
|
||||
|
||||
if (count($pk) === 1) {
|
||||
if ($pk && count($pk) === 1) {
|
||||
$field = key($pk);
|
||||
|
||||
$this->select(Common\Sql::function('COUNT', Common\Sql::raw("DISTINCT " . $this->entityClass::field($field))));
|
||||
|
Loading…
x
Reference in New Issue
Block a user