我正在尝试更新AJAX
public function reorderApplications(Request $request)
{
if (!$request->isXmlHttpRequest()) {
return new JsonResponse(array('message' => 'You can access this only using Ajax!'), 400);
}
$from = $request->request->get('from');
$to = $request->request->get('to');
$em = $this->getDoctrine()->getManager();
/** @var Application $fromApplication */
$fromApplication = $em->getRepository('IndexBundle:Application')->find($from['application']);
/** @var Application $toApplication */
$toApplication = $em->getRepository('IndexBundle:Application')->find($to['application']);
try {
$fromApplication->setOrder($to['position']);
$toApplication->setOrder($from['position']);
$em->flush();
$response = array(
'response' => 'success',
'message' => 'Applications were reordered successfully.'
);
} catch (\Exception $e) {
$response = array(
'response' => 'error',
'message' => $e->getMessage()
);
}
return new JsonResponse($response, 200);
}
最终,try
在$em->flush()
失败,我收到错误:
执行'UPDATE application SET order =时发生异常 ? WHERE id =?' with params [“3”,4]:↵↵SQLSTATE[42000]:语法错误 或访问冲突:1064您的SQL语法有错误;校验 与您的MySQL服务器版本对应的手册 在'order ='3'WHERE id = 4'第1行附近使用的语法
任何人都知道可能出现什么问题?
答案 0 :(得分:2)
order是mysql中的保留关键字。尝试重命名该字段。
答案 1 :(得分:2)
order
是SQL中的保留关键字。
要在列名中使用它,必须将反引号放在定义中:
@Column(name="`order`")