-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
When translating entities that contain unique fields (e.g. uuid, slug), the current translation process copies these values 1:1 to the new translation.
This leads to unique constraint violations on the database level:
uuid→ copied, violatesUNIQUEslug→ copied, violatesUNIQUE
Attributes like #[EmptyOnTranslate] or #[SharedAmongstTranslations] do not solve this problem for unique fields.
Example
#[ORM\Column(type: "string", length: 255, unique: true)]
private string $slug;When creating a translation, the slug value is copied → UNIQUE constraint failed.
Possible Solutions
-
Schema-based fix (quick solution):
Use a composite unique index onslug+localeinstead of a globaluniqueonslug.
See Quick Fix for unique fields in the README.#[ORM\UniqueConstraint( name: "uniq_slug_locale", columns: ["slug", "locale"] )]
-
Bundle improvement (long-term):
Add a handler for unique fields in the translator:- Respect
#[EmptyOnTranslate]→ set field toNULL - Regenerate new values for
uuidorslug(e.g. viaSluggerInterface,Uuid::v4()) - Throw a clear exception if no strategy is possible
- Respect
Why it matters
Without handling unique fields, entities with slugs or UUIDs cannot be translated safely.
Supporting this would make the bundle more robust for real-world use cases.