I'm trying to find an item and update it if it exists, or to create a new one if it does not exist. However, for some reason it seems to be trying to create a new object instead of updating in the event that that already exists in the database.
$object = ObjectItem::firstOrNew(array('object_item_id'=>$userEditedObject['object_item_id'], 'object_id'=>$object_id));
$object->setFields($userEditedObject);
if($object->save()){
return TRUE;
} else {
return FALSE;
}
That code appears to be producing the error
"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '113' for key 'PRIMARY'
This is strange, because I have used this before and it worked okay -- it just seems to be in this particular case.