From 667c1fe9abf12751ab1f55094d69d9043ee80e33 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 31 Oct 2023 18:04:49 +0000 Subject: [PATCH] - Fixed an alias problem within deleteFromPk() method --- src/EntityTrait.php | 7 +++++-- src/Repository.php | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/EntityTrait.php b/src/EntityTrait.php index 26a8723..ae86450 100644 --- a/src/EntityTrait.php +++ b/src/EntityTrait.php @@ -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] diff --git a/src/Repository.php b/src/Repository.php index 9fc7f2b..1dcb8b4 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -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