I have changed the defaultOrder in the search function of a model from one column to another one, and now I’m getting the following error when trying to call that model and trying to create a default object from it:
Creating default object from empty value
Really, the only thing I do is changing that column, and it does exist.
Here is how the model’s search function’s relevant bit looks like:
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'t.create_time DESC',
),
)
);
And here is how I call it in the controller:
$model = Something::model()->activeStatus()->findByPk($id);
$model->modified_flag = 1; // <--- This is the line the error points to
$model->update_usr_id = Yii::app()->user->id;
$model->update_time = time();
$model->save();
Yes, [font="Courier New"]$id[/font] does exist, and is a valid primary key. Again, this all works perfectly fine if I use [font="Courier New"]create_time[/font] for the [font="Courier New"]defaultOrder[/font], but breaks (causes the above error) if I use [font="Courier New"]update_time[/font] for example.
Any ideas what this could be caused by?
EDIT #1 (Jan 13, 2016, 21:39 CET):
Here are the contents of [font="Courier New"]activeStatus()[/font] (this is added to my base model and is used very often throughout the site when calling models):
public function activeStatus()
{
$this->getDbCriteria()->mergeWith(array(
'condition' =>'t.status_id=:status_id',
'params'=>array(
':status_id'=>Types::$status['active']['id'],
),
));
return $this;
}
EDIT #2 (Jan 13, 2016, 21:59 CET):
Ok, I thought I was adding sufficient information to find the root cause of this, but apparently I wasn’t.
The summarise what I’m doing: the function in the controller is an action serving an ajax call. I pass the [font=“Courier New”]model[/font] and [font=“Courier New”]id[/font] variables over from the call when a check box is checked in a list. Again, this works perfectly fine when the column in defaultOrder is create_time, but when I change this to update_time it gives the error.
What we know for sure is that some of the records in the db have null for update_time, but normally that should just mean they come to the beginning of the list (in case of DESC), but I see no reason why that would make $model to become null.