如何在创建新实体期间插入多个翻译
我将 Doctrine 2 与 behavioral-extensions 一起使用(特别是树、可翻译和可翻译)
在示例中,通过首先存储文章、找到它然后进行翻译来进行新翻译。
// first load the article
$article = $em->find('Entity\Article', 1 /*article id*/);
$article->setTitle('my title in de');
$article->setContent('my content in de');
$article->setTranslatableLocale('de_de'); // change locale
$em->persist($article);
$em->flush();
是否可以将文章与翻译一起创建?
我已经尝试过
//assuming the translationListener has default locale en_us
$article = new Article;
$article->setTitle('my title in en_us');
$article->setContent('my content in en_us');
$em->persist($article);
$article->setTranslatableLocale('de_de')
$article->setTitle('my title in german');
$article->setContent('my content in german');
$em->persist($article);
$em->flush();
但这会导致文章表和翻译表中都有德语内容。
如何在创建新实体期间插入多个翻译?
I'm using Doctrine 2 with the behavioral-extensions (in particular Tree, Sluggable and Translatable)
In the examples a new translation is made by first storing an article, finding it and then making a translation.
// first load the article
$article = $em->find('Entity\Article', 1 /*article id*/);
$article->setTitle('my title in de');
$article->setContent('my content in de');
$article->setTranslatableLocale('de_de'); // change locale
$em->persist($article);
$em->flush();
Is it possible to create an article together with it's translation?
I've tried
//assuming the translationListener has default locale en_us
$article = new Article;
$article->setTitle('my title in en_us');
$article->setContent('my content in en_us');
$em->persist($article);
$article->setTranslatableLocale('de_de')
$article->setTitle('my title in german');
$article->setContent('my content in german');
$em->persist($article);
$em->flush();
But this results in German content in both the article-table and the translation-table.
How can I insert multiple translations during the creation of a new entity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有测试过它,但也许你也应该在第一次调用
persist
之前刷新你的entityManager,这样监听器就会收到两个不同的对象(好吧,实际上在两个不同的地方更新了同一个对象)I haven't tested it, but maybe you should flush your entityManager before the first call to
persist
too, so the listener receives two different objects (well, in fact the same object updated at two different places)