Duplicate entry '2' for key 'PRIMARY' on Auto Modeller Update Function in Kohana
문제
Am trying to perform an update and nothing seems to work. It has something to do with my callback I suppose as the update works well when the callback is disabled. This is my try block.
try{
$updatestat=NULL;
$updateresult=NULL;
$id = Arr::get($_POST, 'id');
$scode=trim(Arr::get($_POST, 'stationcode'));
$sname=trim(Arr::get($_POST, 'stationname'));
$dsupdate = new Model_Dstations($id);
$dsupdate->scode = $scode;
$dsupdate->sname = $sname;
$validation = new Validation($_POST);
$validation->rule('scode', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
$validation->rule('sname', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
$result['sql']=$dsupdate->save($validation);}
해결책
Your code looks like a complete mess. Try this:
$dsupdate = new Model_Dstations($id);
$validation = new Validation($_POST);
$validation->rule('scode', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
$validation->rule('sname', array($dsupdate, 'check_updatecheck' ), array( ':validation', ':value',':field',$id ));
if ($validation->check()) {
$dsupdate->scode = $scode;
$dsupdate->sname = $sname;
$dsupdate->save();
}
제휴하지 않습니다 StackOverflow