Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-144

laravel-mongodb - Issue #2725: First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null"

    • Type: Icon: Question Question
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Laravel

      clarkeash has created Issue #2725: First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null" in laravel-mongodb. This Jira ticket was filed by GromNaN

      Issue Text:

      • Laravel-mongodb Version: 4.1.1
      • PHP Version: 8.3.2
      • Database Driver & Version: 1.17.2

      Description: I am currently upgrading to Laravel 10 and v4 of this library and when calling save on an embeded document I get the error: `First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null"`

      Steps to reproduce

      I have the following models (simplified for clarity)
      ```php
      class Account extends Model {
      public function stripe(): EmbedsOne

      { return $this->embedsOne(Stripe::class); }

      }
      ```

      ```php
      class Stripe extends Model {}
      ```

      Then when I try to update the stripe subdocument like so:
      ```php
      $account = Account::find(...);
      $stripe = $account->stripe;
      $stripe->subscription = ['some data'];
      $stripe->save();
      ```

      Expected behaviour

      Tell us what should happen `jenssegers/mongodb` 3.9 it would save the data just fine.

      Actual behaviour

      ```
      1) Tests\Feature\Actions\Stripe\CancelPendingChangeTest::it_will_cancel_a_pending_modification
      InvalidArgumentException: First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null"

      /Users/clarkeash/code/sites/billing/vendor/mongodb/laravel-mongodb/src/Query/Builder.php:1012
      /Users/clarkeash/code/sites/billing/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:302
      /Users/clarkeash/code/sites/billing/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1254
      /Users/clarkeash/code/sites/billing/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1213
      /Users/clarkeash/code/sites/billing/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1130
      /Users/clarkeash/code/sites/billing/vendor/mongodb/laravel-mongodb/src/Eloquent/Model.php:737
      /Users/clarkeash/code/sites/billing/app/Actions/Stripe/StoreSubscriptionInformation.php:82
      /Users/clarkeash/code/sites/billing/vendor/lorisleiva/laravel-actions/src/Concerns/AsObject.php:24
      /Users/clarkeash/code/sites/billing/tests/Feature/Actions/Stripe/CancelPendingChangeTest.php:41
      ```

      I am unsure if this is a bug or if I have missed something, can you point me in the right direction? Thanks

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: