I'm using a MySql database, so I defined the column type as Tinyint(1) in db schema.
In my ActiveRecord I've set boolean validator. Save logic is working as expected.
What I wanted now is that when I call Yii2 REST service, return boolean field as true or false instead 1 or 0, because on the client side the framework comes with strict comparison (===) and 1 is not the same as true.
Of course I could overwrite the value manually before sending the content, or on the client side before loading it into the model, but I would appreciate a cleaner solution.
Inside afterFind i would modify the values from 0 or 1 to true or false:
public function afterFind() {
$this->booleanField = ($this->booleanField === 1);
parent::afterFind();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With