Skip to content

prepare() on null when massive update #102

@Engveloper

Description

@Engveloper

Hello @roblesterjr04,

Thank you very much for your work in this package!.

I am reaching you because I am having an issue when I do a massive update in a query over a HasMany relationship.

$organization->affiliations()
            ->whereIn('Affiliated_Role__c', [Affiliation::APPROVER_ROLE, Affiliation::COORDINATOR_ROLE])
            ->whereNotIn('npe5__Contact__c', $newContactsIds)
            ->where(function ($query) {
                $query->whereNull('npe5__Status__c')
                    ->orWhere('npe5__Status__c', '<>', Affiliation::STATUS_FORMER);
            })->update([
                'npe5__EndDate__c' => now()->toDateString(),
                'npe5__Status__c' => Affiliation::STATUS_FORMER,
            ]);

When I run it, I am getting this exception

[2023-08-04 20:21:00] local.ERROR: Error: Call to a member function prepare() on null in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:566
Stack trace:
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(753): Illuminate\Database\Connection->Illuminate\Database\{closure}('update npe5__Af...', Array)

Debugging the query, in this case there isn't any record to update. Thanks in advance!.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions