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

weird behavior of findAll #67

Open
backend-eigital opened this issue Nov 24, 2017 · 6 comments
Open

weird behavior of findAll #67

backend-eigital opened this issue Nov 24, 2017 · 6 comments
Milestone

Comments

@backend-eigital
Copy link

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
@rob006
Copy link

rob006 commented Nov 26, 2017

Thats because findAll() works in the same way as find() - the key-word here is "find" not "all".

@backend-eigital
Copy link
Author

backend-eigital commented Nov 27, 2017

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().

@cebe
Copy link
Member

cebe commented Nov 27, 2017

did you read the documentation of the methods?

@backend-eigital
Copy link
Author

backend-eigital commented Nov 28, 2017

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.

@backend-eigital
Copy link
Author

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.

@samdark samdark transferred this issue from yiisoft/yii2 Apr 24, 2019
@Tigrov Tigrov added this to the 1.0.0 milestone Jan 21, 2025
@Tigrov
Copy link
Member

Tigrov commented Jan 21, 2025

Related #344

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

No branches or pull requests

4 participants