-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Allow relational operators (>, <, <>) when specifying select conditions #2315
Comments
->andWhere('plz > 40000']) Should be ->andWhere('plz > :plz',[':plz' => 40000]); Dont see any profit from adding this, since there no custom operators that can not be supported by rdbms, can you show some other use cases? |
Right, that's a a way to set the value. But the column will still not be quoted. |
well, this is true, and is bug, should be fixed. For example: Users::find()->andWhere('login = :login',[':login' => 'bernier.marcella.someone'])->one()
// SELECT * FROM "users" WHERE login = 'bernier.marcella.someone' column
can you give an example of that use case? |
There is no special use case. I'm just wondering why some relational operators are supported and others not. Why not just accept every operator and let the database do the job. If the operator is invalid you'll get an error message from the database. $adrs= \frontend\models\Adresse::find()
->andWhere(['like','adr','hotel'])
->andWhere(['between','plz', '40000', '80000'])
->andWhere('aend_dat > "2000-01-01"')
->all(); The example shows that syntax is differnet for field aend_dat and that you also need to pay attention to qoute the value when it is a non numeric data type. |
@samdark but that docs refers to the example when i manually create query string, building it with methods is just another case, it was quoted in Yii1, why not quote it in Yii2? or i missed something? |
Same in your case. Here's manual creating a string: Users::find()->andWhere('login = :login',[':login' => 'bernier.marcella.someone'])->one() And here's not manual: Users::find()->andWhere(['login' => 'bernier.marcella.someone'])->one() |
Oh, ok then, can you add to docs that my above example is also counted as manual creating and will not be qouted? |
Will do. The original request is valid as well, need to think about adding more operation shortcuts. |
Vote for the feature. Having the same approach for most used comparison operators would be fine:
At list something like this could be added to
About |
Fixed. |
I'll take care of the rest of the issue today. |
It should. You're very welcome to check it. |
It works, thank you! |
Operator '!=' not working when attribute value is null. andWhere(['!=', 'attr', 'value']) |
that is expected because the operator is passed directly to the SQL. If you need more magic, you can use |
Only a limited number of relational operatorts can be set when specifying select conditions.
The basic relational operators like <, >, <> and others like 'least' are not supported.
works well but
should also be possible.
Right now you have to write
->andWhere('plz > 40000'])
The text was updated successfully, but these errors were encountered: