I have a model that uses an alphanumeric field as an ID. Yii is throwing a 400 error when I try to update an item through the Gii generated code.
Here’s my loadModel method, the id is not being typecasted to int like some forum posts mention.
public function loadModel($id)
{
$model=Item::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
You should reconsider using that alphanumeric key in your db. Pks should be independent, system generated values that ensure a record/row will be unique even if business rules change. This alpha numeric value should perhaps be a unique constraint instead.
As a bonus, it would eliminate the problem you are having.
I appreciate your response, but that is not an option I would like to take. I assure you the values will be unique. I belive working around the problem is not solving the problem.