原则 - 通过这种关系发现了一个新的实体 [英] Doctrine - A new entity was found through the relationship

查看:251
本文介绍了原则 - 通过这种关系发现了一个新的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自2周以来,我们在尝试刷新新元素时遇到此问题:

since 2 weeks, we are having this problem while trying to flush new elements:


CRITICAL:Doctrine\ORM\ORMInvalidArgumentException :

CRITICAL: Doctrine\ORM\ORMInvalidArgumentException:

通过关系Comment#capture找不到新实体,该关系未配置为级联实体的持久性操作

A new entity was found through the relationship 'Comment#capture' that was not configured to cascade persist operations for entity

但$ 捕获已经在数据库中,我们通过一个 findOneBy ,所以如果我们级联持久化,或坚持下来,我们得到一个

But the capture is already in the database, and we are getting it by a findOneBy, so if we cascade persist it, or persist it, we get a


表约束违规:重复条目。 / p>

Table constraint violation: duplicate entry.

注释是在一个循环中创建的,具有不同的捕获,新的和所有必需的字段都被设置。

The comments are created in a loop with differents captures, with a new, and all required field are set.

如果所有实体持久化和/或获得了一个 findOne (并且全部有效),则刷新仍然失败。

With all of the entities persisted and / or got by a findOne (and all valid), the flush still fails.

我一直在这个问题上,所以请帮助我

I'm on this issue since a while, so please help me

推荐答案

我有同样的问题,它是相同的 EntityManager 。我想插入一个对象相关的 ManyToOne 。我不想要一个级联 坚持

I had the same problem and it was the same EntityManager. I wanted to insert an object related ManyToOne. And I don't want a cascade persist.

示例:

$category = $em->find("Category", 10);

$product = new Product();
$product->setCategory($category)

$em->persist($product);
$em->flush();

这对我来说同样的异常。

This throws the same exception for me.

所以解决方案是:

$category = $em->find("Category", 10);

$product = new Product();
$product->setCategory($category)

$em->merge($product);
$em->flush();

这篇关于原则 - 通过这种关系发现了一个新的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆