mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Home Page:https://www.mongodb.com/compatibility/mongodb-laravel-integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

First argument of MongoDB\Laravel\Query\Builder::where must be a field path as "string". Got "null"

clarkeash opened this issue · comments

  • 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)

class Account extends Model {
public function stripe(): EmbedsOne
    {
        return $this->embedsOne(Stripe::class);
    }
}
class Stripe extends Model {}

Then when I try to update the stripe subdocument like so:

$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

Hi, we have a test for the embedOne feature, but it seems that your use-case is not covered.

Tracking this issue in Jira to investigate. PHPORM-144

This exception was introduced in #2642 063d73f

I've been unable to reproduce the bug by creating a model similar to yours.

Strange, I will try and put together a reproducible case for you

Hi @clarkeash, were you able to find a reproducer?

Closing as I can't reproduce. I can reopen if you can provide a reproducer.

Okay fair enough, I have not had the time to reproduce it as I have a workaround.