Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Translations] No inserts, no reference (Symfony 6) #770

Open
fabpico opened this issue Aug 30, 2024 · 0 comments
Open

[Translations] No inserts, no reference (Symfony 6) #770

fabpico opened this issue Aug 30, 2024 · 0 comments

Comments

@fabpico
Copy link

fabpico commented Aug 30, 2024

First time I use DoctrineBehaviors. I would highly appreciate a bit of automatism for translation handling.
I noticed that after flush, the translations are not being persisted into the database, and also the referencing is missing.

My packages

    "symfony/runtime": "^6.2",
    "symfony/http-kernel": "^6.2",
    "symfony/framework-bundle": "^6.2",
    "symfony/console": "^6.2",
    "symfony/dotenv": "^6.2",
    "symfony/security-bundle": "^6.2",
    "doctrine/doctrine-bundle": "^2.12",
    "doctrine/orm": "^2",
    "knplabs/doctrine-behaviors": "^2.6.2",

Note: I had to downgrade ORM from v3 to v2 in order go get latest doctrine-behaviors (see #757 (comment) )

Screenshot 2024-08-30 102928

So flush did not persist the translations, for that I found #525. This at least inserted the translations, but this is not the official way. Anyway the tables are not referenced, for that I found #532, which talks about expecting columns locale, translatable_id, which would make sense. He talks about registering the bundle to config/bundles.php, but this does not fix the issue.

I ended up testing with 1:1 code from the docs https://github.com/KnpLabs/DoctrineBehaviors/blob/master/docs/translatable.md.

When I do php bin/console doctrine:schema:update --dump-sql

I receive

CREATE SEQUENCE CategoryTranslation_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE SEQUENCE Category_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE CategoryTranslation (id INT NOT NULL, description VARCHAR(255) NOT NULL, fieldsYouNeedToTranslate VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE TABLE Category (id INT NOT NULL, someFieldYouDoNotNeedToTranslate VARCHAR(255) NOT NULL, PRIMARY KEY(id));

There is no referencing to each other.

I register the bundle

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    \Knp\DoctrineBehaviors\DoctrineBehaviorsBundle::class => ['all' => true], // <--
];

Nothing changed, except the ordering of the lines.

CREATE SEQUENCE Category_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE SEQUENCE CategoryTranslation_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
CREATE TABLE Category (id INT NOT NULL, someFieldYouDoNotNeedToTranslate VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE TABLE CategoryTranslation (id INT NOT NULL, description VARCHAR(255) NOT NULL, fieldsYouNeedToTranslate VARCHAR(255) NOT NULL, PRIMARY KEY(id));

Note: I don’t use Flex (and maybe never want to)

For smell of package version problems I downgraded doctrine-behaviors to v1 (^1 installed 1.4.1 but latest v1 version is 1.6.1) and I used 1.4.1 docs https://github.com/KnpLabs/DoctrineBehaviors/tree/1.4.1?tab=readme-ov-file#translatable .

Without registering the bundle, I get

CREATE TABLE CategoryTranslation (id INT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE TABLE Category (id INT NOT NULL, someFieldYouDoNotNeedToTranslate VARCHAR(255) NOT NULL, PRIMARY KEY(id));

Assuming it needs bundle registration to generate the references, I register it

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
//    \Knp\DoctrineBehaviors\DoctrineBehaviorsBundle::class => ['all' => true], // v2
    \Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle::class => ['all' => true], // v1
];

But it seems not to be compatible with Symfony 6.

Fatal error: Declaration of Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle::getContainerExtension() must be compatible with Symfony\Component\HttpKernel\Bundle\Bundle::getContainerExtension(): ?Symfony\Component\DependencyInjection\Extension\ExtensionInterface in /home/api/vendor/knplabs/doctrine-behaviors/src/Bundle/DoctrineBehaviorsBundle.php on line 10

So I should stick to DoctrineBehaviors v2 but it’s not generating references.

Any fix for this? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant