From a7466e9b5218d7a2899322d5218885b0c47c79c2 Mon Sep 17 00:00:00 2001 From: William Arin Date: Tue, 5 Dec 2023 11:46:21 +0100 Subject: [PATCH] fix: bug in where condition when persisting entity --- src/Bridge/Repository/AbstractEntityRepository.php | 2 +- test/Test/Bridge/Repository/PostRepositoryTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Repository/AbstractEntityRepository.php b/src/Bridge/Repository/AbstractEntityRepository.php index b2889f7..b8b6e44 100644 --- a/src/Bridge/Repository/AbstractEntityRepository.php +++ b/src/Bridge/Repository/AbstractEntityRepository.php @@ -206,7 +206,7 @@ public function persist(mixed $entity): void $queryBuilder = $this->entityManager->getConnection() ->createQueryBuilder() ->update($this->entityManager->getTablesPrefix() . static::TABLE_NAME) - ->where(static::TABLE_IDENTIFIER, ':' . static::TABLE_IDENTIFIER) + ->where(static::TABLE_IDENTIFIER . ' = :' . static::TABLE_IDENTIFIER) ->setParameter(static::TABLE_IDENTIFIER, $entity->{static::TABLE_IDENTIFIER}) ; diff --git a/test/Test/Bridge/Repository/PostRepositoryTest.php b/test/Test/Bridge/Repository/PostRepositoryTest.php index d7fea3e..234b9a1 100644 --- a/test/Test/Bridge/Repository/PostRepositoryTest.php +++ b/test/Test/Bridge/Repository/PostRepositoryTest.php @@ -267,6 +267,10 @@ public function testPersistExistingPost(): void self::assertSame('Another post with a new title', $post->postTitle); self::assertSame('publish', $post->postStatus); + + // Assert no collateral damages + $anotherPost = $this->repository->find(10); + self::assertSame('A post', $anotherPost->postTitle); } public function testDynamicSetter(): void