weird behavior of findAll
it is weird why findAll() method should behave different from all other xxxAll()
Table::findAll(
[
'id' => 123,
'check' => true,
['OR', ['userId' => 123], ['userId' => 0]],
]
);
What is the expected result?
SELECT * FROM `table` WHERE `id` = 123 AND check = 'true' AND (userId = 0 OR userId = 123)
What do you get instead?
SELECT * FROM `table` WHERE `id` IN (123, 'true', NULL)
Additional info
deleteAll command work as expected and its really weird why thing behave differently and if it want to change the query why it doesn't just throw an exception. like where() which throw exception when we call it with same array
Table::find()->where(
[
'id' => 123,
'check' => true,
['OR', ['userId' => 123], ['userId' => 0]
],
])->all();
| Q | A |
|---|---|
| Yii version | 2.0.13 |
| PHP version | 7.1 |
| Operating system | Debian 9 |
Thats because findAll() works in the same way as find() - the key-word here is "find" not "all".
so let me ask my question in a new way why they should have different behaviour at all.
still not make sense to me to have things under the concept of finding something (either in findAll() or updateAll() and etc.) but with different behaviour here we only focus on condition part of xxxAll().
did you read the documentation of the methods?
Yes @cebe, I read it but problem is not in misunderstanding or wrong usage problem is not having a uniform for all/one conditional queries. as developer you know how difficult is to remember things but to make it more developer friendly we can simply have same uniform for all of the All/One queries and prevent this kind of mess.
it's like this situation suppose you have a getItemNameById() and getItemDescriptionById() as a developer you expect both function accept same argument and behave similar of course their functionality is different but you generally expect to send same argument to both of them.