cakephp-fixture-factories icon indicating copy to clipboard operation
cakephp-fixture-factories copied to clipboard

Creating multiple translations using shadowStrategy

Open mcube27 opened this issue 2 years ago • 1 comments

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

mcube27 avatar Dec 23 '22 11:12 mcube27

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?

pabloelcolombiano avatar Jan 24 '23 21:01 pabloelcolombiano