vierge-noire / cakephp-fixture-factories

CakePHP Fixture Factories
https://vierge-noire.github.io/
MIT License
83 stars 21 forks source link

Creating multiple translations using shadowStrategy #195

Open mcube27 opened 1 year ago

mcube27 commented 1 year ago

Hi,

I have an article with translated name and description. I use the shadow strategy.

If I want to create multiple translations for an article, I need to pass this:

$article = ArticleFactory::make()
            ->withArticlesTranslations(
                [
                    [
                        'id' => 1,
                        'locale' => 'fr',
                        'name' => 'Français',
                        'description' => 'Une phrase',
                    ],
                    [
                        'id' => 1,
                        'locale' => 'en',
                        'name' => 'English',
                        'description' => 'A sentence',
                    ],
                ]
            )
            ->persist();

If I do this, the translations do persist in the database and the id is corrected by cakephp to the article id.

I I omit the 'id', then the translation do not get persisted.

It does not feel intuitive nor very nice to add an id that doesn't mean anything.

I use Cakephp 4.4

pabloelcolombiano commented 1 year ago

Hi,

normally you should not need to add this id. How is the association between Articles and ArticlesTranslationsdefined in the ArticlesTable and in the ArticlesTranslationsTable?