Why Controller is trying to insert new record?


I have this code:

$companymodel = Company::findOne(1);

$companymodel->days_left = 45;


It fails saying that the company email already exists? The error is correct based on my validations in the Company model, but should the code above not just do an update on the paid DB column and ignore the rest?

Don’t worry, I changed to:

$companymodel = Company::find(1);

And working fine. Still need to get my head around find and findOne.

And then I run into another error.

2015-02-17 10:07:16 [][-][-][error][yii\base\UnknownPropertyException] exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\db\ActiveQuery::days_left' in /usr/www/users/stariurbyb/vendor/yiisoft/yii2/base/Component.php:197

Stack trace:

#0 /usr/www/users/stariurbyb/controllers/PaymentController.php(26): yii\base\Component->__set('days_left', 45)

#1 [internal function]: app\controllers\PaymentController->actionNotifypayfast()

#2 /usr/www/users/stariurbyb/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)

#3 /usr/www/users/stariurbyb/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)

#4 /usr/www/users/stariurbyb/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('notifypayfast', Array)

#5 /usr/www/users/stariurbyb/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('payment/notifyp...', Array)

#6 /usr/www/users/stariurbyb/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

#7 /usr/www/users/stariurbyb/web/index.php(12): yii\base\Application->run()

#8 {main}

PLEASE help.

it seems you don’t have days_left in Company table or in Company model


It is definitely in my Company table and this is in my model:

 * @property integer $days_left




    public function rules()


        return [

            [['days_left'], 'integer'],

I did create the controller class myself and not using the Gii tool. Could that be a problem?