我有一个带有fos restbundle的Symfony rest api构建,我正在反序列化json PUT请求,以便更新具有to-many关系的doctrine实体.但是,配置的to-many子对象orphanremoval=true在json数据中不存在时不会从数据库中删除.
PUT请求有效负载:
{
"id": 1,
"name":"Some name",
"export_destinations": [
{
"id": 1,
"type": "USER_STORAGE",
"user": {"id": 5}
}
{
"id": 2,
"type": "SYSTEM_STORAGE"
}
]
}
Run Code Online (Sandbox Code Playgroud)
控制器动作:
/**
* @Rest\Put("{id}")
* @ParamConverter(
* "exportJob",
* converter="fos_rest.request_body",
* options={"deserializationContext"={"groups"={"put"}}}
* )
* @Rest\View(serializerGroups={"details"})
* @param ExportJob $exportJob
* @return ExportJob
*/
public function putAction(ExportJob $exportJob)
{
$this->getManager()->persist($exportJob);
$this->getManager()->flush();
return $exportJob;
}
Run Code Online (Sandbox Code Playgroud)
ExportJob实体
/**
* @ORM\Entity()
*/
class ExportJob
{
/**
* @var ArrayCollection|ExportDestination[]
*
* …Run Code Online (Sandbox Code Playgroud)