Doctrine orm Symfony 4:通过反序列化实体更新现有实体会导致新的相关项或ORMInvalidArgumentException
这是我在Stackoverflow.com上的第一个问题,在我写信之前。首先,控制器功能:Doctrine orm Symfony 4:通过反序列化实体更新现有实体会导致新的相关项或ORMInvalidArgumentException,doctrine-orm,deserialization,symfony4,fosrestbundle,Doctrine Orm,Deserialization,Symfony4,Fosrestbundle,这是我在Stackoverflow.com上的第一个问题,在我写信之前。首先,控制器功能: /** * @Rest\Patch("/identifiers/v2/{id}") * * @ParamConverter("identifier") * @ParamConverter("identifierPatch", converter="fos_rest.request_body") */ public function patchAction(Identifier $identifi
/**
* @Rest\Patch("/identifiers/v2/{id}")
*
* @ParamConverter("identifier")
* @ParamConverter("identifierPatch", converter="fos_rest.request_body")
*/
public function patchAction(Identifier $identifier, Identifier $identifierPatch)
{
$identifier->setLandingPage($identifierPatch->getLandingPage());
$identifier->setIdentifier($identifierPatch->getIdentifier());
$identifier->setIsUsed($identifierPatch->getIsUsed());
$this->entityManager->flush();
/**
* Just for debugging...
*/
$view = $this->view([
'identifier' => $identifier,
'identifierPatch' => $identifierPatch
]);
return $this->handleView($view);
}
当我尝试以这种方式更新现有实体时,会得到一个或InvalidargumentException,并显示一条消息“通过关系(…)找到了一个新实体”
当我在相关实体上设置cascade={“persist”}
时:
/**
* @ORM\ManyToOne(targetEntity="App\Entity\LandingPage", inversedBy="identifiers")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotNull()
* @Serializer\Type("App\Entity\LandingPage")
*/
private $landing_page;
。。。相关实体将作为新实体插入,这不是我要寻找的
我可以使用$this->entityManager->merge($identifier)
,但这不是我想要的,因为我将来需要进行一些手动验证,我希望返回实体作为响应(相关实体在未更新时将为空)和$this->entityManager->merge()
将在原则3中被弃用
问题:有没有办法用反序列化实体更新给定实体
您好,
丹尼恩德
编辑(1): 嗯,我想我找到了解决这个“问题”的办法 服务.亚马尔
jms_serializer.object_constructor:
alias: jms_serializer.doctrine_object_constructor
public: false
现在我没有得到任何异常,相关实体将不会作为新实体插入