I have a table categories with a child table cat_lan (title per language)
So I am trying tom use the Collecting Tabular Input of docs
But I have the error Integrity constraint violation: 1062 Duplicate entry ‘0-48’ for key ‘PRIMARY’ .
It is obvious that is is trying to insert new value and not to update.
How can I fix it?My code
$cat_lan=cat_lan::model()->getitemstoupdate($model->cat_id);
.....
foreach($cat_lan as $i=>$item) {
if(isset($_POST['cat_lan'][$i]))
$item->attributes=$_POST['cat_lan'][$i];
$item->cat_id=$model->cat_id;
$item->save();
}
....
public function getitemstoupdate($cat_id) {
$sql="select lan_id,cat_name from cat_lan where cat_id=$cat_id";
$command=Yii::app()->db->createCommand($sql);
$dataReader=$command->query();
// $i=0;
$rows=array ();
foreach($dataReader as $row) {
$rows[$row['lan_id']]=new cat_lan;
$rows[$row['lan_id']]->lan_id=$row['lan_id'];
$rows[$row['lan_id']]->cat_name=$row['cat_name'];
}
return $rows;
}