feat(model): make translation auto-creation on read configurable - #87
Merged
Conversation
getTranslation() creates and attaches a translation whenever both the requested and the fallback locale are missing; with the documented cascade: persist mapping, a read can then insert empty translation rows on the next flush or die on not-null columns (Locastic#55, Locastic#34, Locastic#32). Add an auto_create_translations option (default true, the 2.0 behavior; the default flips to false in 3.0, and leaving the option unset is deprecated since 2.1). AssignLocaleListener stamps it onto loaded and persisted translatables, like it already does with the locales. When disabled, getTranslation() returns a detached translation for a missing locale: reads still see empty fields but nothing is attached, cached or persisted. Virtual setters need an explicit write target once auto-creation is off, so the trait gains getOrCreateTranslation(): it creates and attaches the missing translation for the exact locale, never falling back (getTranslation()'s fallback would hand setters the fallback translation and let them overwrite its content), regardless of the option. The README setter example now writes through it, and the context7 rules cover the new setter pattern and recommend disabling auto-creation. The deprecated ApiPlatformTranslationExtension hardcodes the bundle parameters, so it sets the new one too, keeping legacy setups compiling.
paullla
force-pushed
the
feat/no-write-on-read
branch
from
July 28, 2026 09:47
f6005d5 to
bf580a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
auto_create_translationsoption +getOrCreateTranslation()auto_create_translationsunset (default flips in 3.0)Problem
getTranslation()creates and attaches a translation whenever both the requested and the fallback locale are missing. With the documentedcascade: persistmapping, a plain read can then insert empty translation rows on the next flush, or die on not-null columns (#55, #34, #32).Changes
auto_create_translationsconfig option.true(default) keeps the 2.0 behavior;falsemakesgetTranslation()return a detached translation for a missing locale: reads still see empty fields, but nothing is attached, cached or persisted. Leaving the option unset triggers a deprecation; the default flips tofalsein 3.0.TranslatableTrait::getOrCreateTranslation(?string $locale): the explicit write target for virtual setters. Targets the exact locale and never falls back (so setters can no longer overwrite the fallback translation's content), attaches regardless of the option. README setter example and context7 rules updated to it.AssignLocaleListenerstamps the flag onto loaded/persisted translatables (same conduit as the locales),method_exists-guarded soTranslatableInterfacegains no method.ApiPlatformTranslationExtensionsets the new parameter too, keeping legacy setups compiling.Verification
composer validate --strictclean.getOrCreateTranslation()persists correctly, invalid config rejected, deprecation logged.