You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I work on api. I use RedisActiveRecord.
I do create request
{
stringValue : '123'
intValue : 20,
boolValue : true
}
I load AR model & save it.
So, model have integer validator for intValue & bool Validator for boolValue
when i do get request
I find model by Id from RedisDB & return $model->toArray().
the ploblem that after loading from DB intValue & boolValue become string '20' & '1'.
Suggestion
Maybe that is not a problem for PHP7. But at this momen i don't have ability to upgrade a php version. I guess, you can face the challenge with other DB & AR.
I'd suggest following solution.
Add method attributeTypes to BaseActiveRecord which return array in following format
[
'attributeName1'=> 'int'
'attributeName2'=> 'bool'
'attributeName3'=> 'string'
]
in __set method we have to verify type of value for attribute & bring it, if it's required.
Additional info
I saw similar solution at Laravel and i find it very usefull.
Q
A
Yii version
2.0.5
PHP version
5.6
Operating system
Ubuntu mate
The text was updated successfully, but these errors were encountered:
The problem
I work on api. I use RedisActiveRecord.
I do create request
{
stringValue : '123'
intValue : 20,
boolValue : true
}
I load AR model & save it.
So, model have integer validator for intValue & bool Validator for boolValue
when i do get request
I find model by Id from RedisDB & return $model->toArray().
the ploblem that after loading from DB intValue & boolValue become string '20' & '1'.
Suggestion
Maybe that is not a problem for PHP7. But at this momen i don't have ability to upgrade a php version. I guess, you can face the challenge with other DB & AR.
I'd suggest following solution.
Add method attributeTypes to BaseActiveRecord which return array in following format
[
'attributeName1'=> 'int'
'attributeName2'=> 'bool'
'attributeName3'=> 'string'
]
in __set method we have to verify type of value for attribute & bring it, if it's required.
Additional info
I saw similar solution at Laravel and i find it very usefull.
The text was updated successfully, but these errors were encountered: