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

Query helper method for filter values containing operators #8505

Closed
wants to merge 14 commits into from

Conversation

lennartvdd
Copy link
Contributor

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:

  • 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'.

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]);
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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 cebe added this to the 2.0.x milestone May 21, 2015
@cebe cebe self-assigned this May 21, 2015
@lennartvdd
Copy link
Contributor Author

@cebe Porting to the NoSQL implementations is a good idea. I've made an attempt in yiisoft/yii2-mongodb#24.
Can you review it? It seems to work, but I've had to add support for arbitrary operators in the conditionBuilders. My experience with MongoDB is limited, so i'm not sure if this might break anything or cause security risks.

@githubjeka
Copy link
Contributor

Probably you need a method orFilterCompare() also.

@lennartvdd
Copy link
Contributor Author

I think orFilterCompare() is not very usefull for the use case in GridView filtering for which this PR is intended, because results would be counterintuitive. Perhaps there is another use case for which it's more usefull?

@acorncom
Copy link
Contributor

acorncom commented Mar 2, 2016

@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! 👍

@cebe
Copy link
Member

cebe commented Mar 3, 2016

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 cebe modified the milestones: 2.0.8, 2.0.x Mar 3, 2016
@acorncom
Copy link
Contributor

acorncom commented Mar 4, 2016

@cebe 👍 Seems like you must have seen it at one point, as it was self-assigned, but that was almost a year ago and you guys have been busy! 😄

@Faryshta
Copy link
Contributor

@lennartvdd can you add this to the guide? it will be easier to review that way

@cebe cebe closed this in f8a844a Apr 22, 2016
@cebe
Copy link
Member

cebe commented Apr 22, 2016

merged, thank you! Keeping #2022 open for documentation.

@sr1234
Copy link

sr1234 commented May 10, 2017

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.

@lennartvdd
Copy link
Contributor Author

Should. Did you try it?

@sr1234
Copy link

sr1234 commented May 10, 2017

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.

@Faryshta
Copy link
Contributor

@sr1234 you should check #14014 since thats rules issue

@sr1234
Copy link

sr1234 commented May 11, 2017

@Faryshta Thank you :)

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

Successfully merging this pull request may close these issues.

None yet

8 participants