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

whereAny and whereAll query Error #2757

Closed
ilejohn-official opened this issue Mar 10, 2024 · 4 comments
Closed

whereAny and whereAll query Error #2757

ilejohn-official opened this issue Mar 10, 2024 · 4 comments
Milestone

Comments

@ilejohn-official
Copy link

  • Laravel-mongodb Version: 4.1.x-dev
  • PHP Version: 8.2.14
  • Database Driver & Version:

Description:

The whereAny and whereAll query are not generating accurate mongo queries as it does in SQL. https://laravel.com/docs/10.x/queries#where-any-all-clauses

Steps to reproduce

  1. perform a whereAny or whereAll query on a collection
  2. chain toMql() to see the query output

Expected behaviour

for example a whereAny query

Model::whereAny(['title','text','shortcut','first_line'], 'like', '%-p%')->toMql();

should look like this

[
 'find' => [
     '$or' => [
            ['title' => new \MongoDB\BSON\Regex('^.*\-p.*$', 'i')],
            ['text' => new \MongoDB\BSON\Regex('^.*\-p.*$', 'i')],
            ['shortcut' => new \MongoDB\BSON\Regex('^.*\-p.*$', 'i')],
            ['first_line' => new \MongoDB\BSON\Regex('^.*\-p.*$', 'i')],
      ],
 ],
]
  

Actual behaviour

Instead this is what I see

[
 'find' => [
    'any' => [
            0 => ['title' => true],
            1 => ['text' => true],
            2 => ['shortcut' => true],
            3 => ['first_line' => true],
        ],
  ]
 ]
@GromNaN
Copy link
Member

GromNaN commented Mar 11, 2024

Thanks for the feedback @ilejohn-official. This new methods have been added last week in Laravel (by laravel/framework#50344). Would you like to open a PR and add it to laravel-mongodb 4.2?

The new methods will be in MongoDB\Laravel\Query\Builder and the tests can be added to MongoDB\Laravel\Tests\Query\BuilderTest

This feature request is tracked in PHPORM-159

@GromNaN GromNaN added this to the 4.1 milestone Mar 12, 2024
@GromNaN
Copy link
Member

GromNaN commented Mar 12, 2024

You need to upgrade to Laravel v10.47+ to get this new feature. Otherwise you fallback to the the dynamicWhere mechanism that doesn't work as you expect.

@GromNaN GromNaN closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2024
@ilejohn-official
Copy link
Author

So the PR is no longer needed, right?

@GromNaN
Copy link
Member

GromNaN commented Mar 12, 2024

I opened #2763 to add tests on this feature. But nothing needs to be done to support this feature as soon as you upgrade to a version of Laravel that supports it.

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

No branches or pull requests

2 participants