namespace yii_app\records;
use Yii;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
/**
* This is the model class for table "motivation".
return 'motivation';
}
+ public function behaviors()
+ {
+ return [
+ [
+ 'class' => TimestampBehavior::class,
+ 'createdAtAttribute' => 'created_at',
+ 'updatedAtAttribute' => 'updated_at',
+ 'value' => new Expression('NOW()'),
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
public function rules()
{
return [
- [['store_id', 'year', 'month', 'updated_at', 'created_at'], 'required'],
+ [['store_id', 'year', 'month'], 'required'],
[['store_id', 'year', 'month'], 'default', 'value' => null],
[['store_id', 'year', 'month'], 'integer'],
- [['updated_at', 'created_at'], 'safe'],
];
}
$motivation = Motivation::find()->where(['store_id' => $store->id, 'year' => $year, 'month' => $month])->one();
/** @var $motivation Motivation */
- if ($motivation) {
- $motivation->updated_at = date('Y-m-d H:i:s');
- } else {
+ if (!$motivation) {
$motivation = new Motivation;
$motivation->store_id = $store->id;
$motivation->year = $year;
$motivation->month = $month;
- $motivation->created_at = date('Y-m-d H:i:s');
- $motivation->updated_at = date('Y-m-d H:i:s');
}
$storeStr = false;