Skip to content

Commit 1bfe150

Browse files
Merge branch '5.4' into 6.0
* 5.4: (26 commits) [Dotenv] Fix testBootEnv() to start from a fresh context fix tests relax expected exception message for forward-compatibility with 5.4 fix expected exception messages after changes made in Definition class [DependencyInjection] show class name on DI errors skip command completion tests with older Symfony Console versions Use GitHub issue form templates Fix CS add ResponseIsUnprocessable Add missing translations for Persian (fa) skip command completion tests with older Symfony Console versions prevent issues with timezones and DST by using only UNIX timestamps Add the missing translations for Bahasa Indonesia (id) [Finder] Fix .gitignore infinite loop Update README.md fix messenger DI dependency for registerAttributeForAutoconfiguration [Messenger] Autoconfigurable attributes Fix deprecations on PHP 8.2 [Dotenv] Fix testLoadEnv() .env.dist isolation Since 5.0, throws \UnexpectedValueException has been removed. ...
2 parents 5bf1273 + 7ab1fb1 commit 1bfe150

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111

1212
* Add `DoctrineOpenTransactionLoggerMiddleware` to log when a transaction has been left open
1313
* Deprecate `PdoCacheAdapterDoctrineSchemaSubscriber` and add `DoctrineDbalCacheAdapterSchemaSubscriber` instead
14+
* `UniqueEntity` constraint retrieves a maximum of two entities if the default repository method is used.
1415

1516
5.3
1617
---

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,18 @@ public function validate(mixed $entity, Constraint $constraint)
134134
$repository = $em->getRepository(\get_class($entity));
135135
}
136136

137-
$result = $repository->{$constraint->repositoryMethod}($criteria);
137+
$arguments = [$criteria];
138+
139+
/* If the default repository method is used, it is always enough to retrieve at most two entities because:
140+
* - No entity returned, the current entity is definitely unique.
141+
* - More than one entity returned, the current entity cannot be unique.
142+
* - One entity returned the uniqueness depends on the current entity.
143+
*/
144+
if ('findBy' === $constraint->repositoryMethod) {
145+
$arguments = [$criteria, null, 2];
146+
}
147+
148+
$result = $repository->{$constraint->repositoryMethod}(...$arguments);
138149

139150
if ($result instanceof \IteratorAggregate) {
140151
$result = $result->getIterator();

0 commit comments

Comments
 (0)