Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict attribute types #11804

Closed
NaLLiFFuNT opened this issue Jun 23, 2016 · 2 comments
Closed

Strict attribute types #11804

NaLLiFFuNT opened this issue Jun 23, 2016 · 2 comments
Assignees
Milestone

Comments

@NaLLiFFuNT
Copy link

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.

Q A
Yii version 2.0.5
PHP version 5.6
Operating system Ubuntu mate
@yii-bot
Copy link

yii-bot commented Jun 23, 2016

Issue moved to yiisoft/yii2-redis#73

@yii-bot yii-bot closed this as completed Jun 23, 2016
@cebe cebe reopened this Jun 23, 2016
@cebe cebe added status:to be verified Needs to be reproduced and validated. and removed ext:redis labels Jun 23, 2016
@cebe cebe self-assigned this Jun 23, 2016
@cebe cebe added this to the 2.0.10 milestone Jun 23, 2016
@klimov-paul klimov-paul added type:enhancement and removed status:to be verified Needs to be reproduced and validated. labels Aug 4, 2016
@klimov-paul
Copy link
Member

Resolved by #12067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants