[英]Doubling records in Doctrine
I have two Entities: 我有两个实体:
The relation in Yaml goes as this: Yaml中的关系如下:
Entity\Test:
type: entity
table: test
repositoryClass: Repositories\TestRepository
id:
id:
type: integer
generator:
strategy: AUTO
fields:
totmpfile:
targetEntity: Entity\TmpFile
$test
is a TestEntity that's already in the database and I got the reference of it in $test
. $test
是数据库中已经存在的TestEntity,我在$test
得到了它的引用。 I get it like: 我得到这样的:
$test = $em->getRepository('Entity\Test')->find($id);
$tmpf = new Entity\TmpFile(); // I'm creating a new Entity
$tmpf->setTitle('Something'); // I'm seting a field for that entity
$em->persist($tmpf); // persisting the entity
$test->addTotmpfile($tmpf); // I'm adding tmpf
$em->persist($test);
$em->flush();
My problem goes about doubling Test entities as I persist the test and then flush it. 我的问题是在我坚持测试然后刷新它时, 将测试实体加倍 。 Any ideas?
有任何想法吗? I just want to update the Entity instead of creating a new one.
我只想更新实体而不是创建一个新实体。 My ideas ran out :/ and I can't find anything suitable for my problem in the documentation.
我的想法用尽了:/,在文档中找不到适合我问题的任何内容。
I'm posting the answer on behalf of the OP: 我代表OP发布答案:
So I found the solution. 所以我找到了解决方案。 The problem was that I was getting repository instead of getting the reference.
问题是我正在获取存储库而不是获取参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.