Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 1.4合并同一对象的2并更新旧记录_Php_Mysql_Symfony 1.4_Doctrine 1.2 - Fatal编程技术网

Php Symfony 1.4合并同一对象的2并更新旧记录

Php Symfony 1.4合并同一对象的2并更新旧记录,php,mysql,symfony-1.4,doctrine-1.2,Php,Mysql,Symfony 1.4,Doctrine 1.2,我有以下问题。我有一个从表单中检索到的对象,我将结果与数据库进行比较,该数据库将表单的旧版本保存为InspectionReport对象 如果存在旧版本的表单,请使用以下方法将新信息与旧信息合并: // $found_inspection_report is the report found in the database, // $inspection_report is the one from the form $found_inspection_report->merge($ins

我有以下问题。我有一个从表单中检索到的对象,我将结果与数据库进行比较,该数据库将表单的旧版本保存为InspectionReport对象

如果存在旧版本的表单,请使用以下方法将新信息与旧信息合并:

// $found_inspection_report is the report found in the database, 
// $inspection_report is the one from the form
$found_inspection_report->merge($inspection_report);
然后,我想将合并后的对象和新值一起保存到数据库中,作为从数据库中找到的旧对象。 因为合并覆盖了$found\u inspection\u报告的ID,所以我首先将旧ID设置回:

$found_inspection_report->setId($old_id);
然后我保存它:

$found_inspection_report->save();
但是我得到了以下错误:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY'

因此,我的问题是,有没有一种方法可以成功地合并,甚至可以在不设置旧ID的情况下,更新/保存数据库中的旧对象/记录,比如ID为1而不是新记录。

使用synchronizeWithArray方法而不是合并。看到这里了吗


我对这个解决方案没什么进展。。。问题是我想用新值更新现有对象。但是,当我尝试同步或合并数据时,id会丢失,它只是用新id保存。如果没有“SQLSTATE[23000]:完整性约束冲突:1062键“PRIMARY”的重复条目“1-1”,我甚至无法保存从数据库检索到的现有对象
$old->synchronizeWithArray($arrayNew);
$old->save();