- Fixed an alias problem within deleteFromPk() method
This commit is contained in:
parent
953fc35680
commit
667c1fe9ab
|
@ -306,9 +306,12 @@ trait EntityTrait {
|
|||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function field($name, null|string|bool $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
public static function field($name, null|string|false $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
{
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : ( $alias === false ? '' : Repository::DEFAULT_ALIAS ), Ulmus::resolveEntity(static::class));
|
||||
|
||||
$default = ( $alias === false ? '' : Repository::DEFAULT_ALIAS ); # bw compatibility, to be deprecated
|
||||
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : $default, Ulmus::resolveEntity(static::class));
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
|
|
|
@ -114,7 +114,7 @@ class Repository
|
|||
throw new Exception\EntityPrimaryKeyUnknown("A primary key value has to be defined to delete an item.");
|
||||
}
|
||||
|
||||
return (bool) $this->wherePrimaryKey($value)->deleteOne()->rowCount;
|
||||
return (bool) $this->wherePrimaryKey($value, null)->deleteOne()->rowCount;
|
||||
}
|
||||
|
||||
public function destroy(object $entity) : bool
|
||||
|
@ -599,7 +599,7 @@ class Repository
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function wherePrimaryKey(mixed $value) : self
|
||||
public function wherePrimaryKey(mixed $value, null|string|bool $alias = self::DEFAULT_ALIAS) : self
|
||||
{
|
||||
if ( null === $primaryKeyField = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() ) {
|
||||
throw new Exception\EntityPrimaryKeyUnknown("Entity has no field containing attributes 'primary_key'");
|
||||
|
@ -607,7 +607,7 @@ class Repository
|
|||
|
||||
$pkField = key($primaryKeyField);
|
||||
|
||||
return $this->where($this->entityClass::field($primaryKeyField[$pkField]->name ?? $pkField), $value);
|
||||
return $this->where($this->entityClass::field($primaryKeyField[$pkField]->name ?? $pkField, false), $value);
|
||||
}
|
||||
|
||||
public function withJoin(string|array $fields, array $options = []) : self
|
||||
|
|
Loading…
Reference in New Issue