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
Query helper method for filter values containing operators #8505
Conversation
Basic implementation proposal for yiisoft#2022 Shortcomings/todo's: * filtering on non-scalars (where IN statements) not supported * Numeric properties with a corresponding validation rule will yield errors when they contain an alphanumeric operator. These properties' rules should be defined as 'string' or 'safe'. * no implementation example in Gii code (yet).
} else { | ||
$op = $defaultOperator; | ||
} | ||
$this->andFilterWhere([$op, $name, $value]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail for NOSQL queries such as yii\elasticsearhc\Query
or yii\mongodb\Query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True.. it's RDBMS specific. Would moving this method out of the generic QueryTrait to yii\db\Query suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could try to port it to the noSQL implementations. Will do that for redis and ES.
@cebe Porting to the NoSQL implementations is a good idea. I've made an attempt in yiisoft/yii2-mongodb#24. |
Probably you need a method |
I think |
Conflicts: framework/CHANGELOG.md
@cebe Any updates on getting this merged in? I can use an override for now (and use the code in the PR), but would love to see it in the framework! 👍 |
Sorry, I do not remember to have seen this one actually :) Set for 2.0.8 milestone, will try to review it for next release. |
@cebe 👍 Seems like you must have seen it at one point, as it was |
@lennartvdd can you add this to the guide? it will be easier to review that way |
merged, thank you! Keeping #2022 open for documentation. |
Does using numeric comparison operators work with decimal data types (mysql decimals)? Would love to be able to filter for instance on employees with hourly rates greater than some number (e.g. >= 50.00). Thanks, S. |
Should. Did you try it? |
I should probably clarify that I am using the Gii generated GridView. Yes, tried it. Gives error: "Hourly Rate Base must be a number." I'm entering '>100.00' in the input for the field in the GridView search. |
@sr1234 you should check #14014 since thats rules issue |
@Faryshta Thank you :) |
Basic implementation proposal for #2022
implementation in Gii CRUD generator in PR yiisoft/yii2-gii#43
implementation in MongoDB extensions in PR yiisoft/yii2-mongodb#24
Shortcomings/todo's:
errors when they contain an alphanumeric operator. These properties'
rules should be defined as 'string' or 'safe'.