Is there a way to subtract a value in a int column to say by 1?I have a button that when it is clicked it will call a function to save the data in the table but I want to know how to subtracting a number in a database using yii 2 I have tried the following code below but it had no effect. Can someone help me how to make math operations in yii 2?
public static function AddSubject($subjectid, $clientid){
$subject = ActiveCurriculum::findOne(['subjectid' => $subjectid]);
$activesubject = new ActiveSubject();
$activesubject->clientid = $clientid;
$activesubject->subjectid = $subject->subjectid;
$activesubject->subjectcode = $subject->subjectcode;
$activesubject->days = $subject->days;
$activesubject->time = $subject->time;
$activesubject->section = $subject->section;
$activesubject->room = $subject->room;
$activesubject->units = $subject->units;
$subject->units = $subject->units - 1; //this should subtract the number
//of slots by 1 but now it is not working.
$activesubject->save();
return true;
//return static::findOne(['subjectid' => $subjectid]);
//->where(['subjectid' => $subjectid]);
}