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

prepare() on null when massive update #102

Open
Engveloper opened this issue Aug 4, 2023 · 2 comments
Open

prepare() on null when massive update #102

Engveloper opened this issue Aug 4, 2023 · 2 comments

Comments

@Engveloper
Copy link

Engveloper commented Aug 4, 2023

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!.

@roblesterjr04
Copy link
Owner

Hi, sorry for the late reply. Seeing as how the trace is reporting use of the Laravel connection class, i'd say the query is being executed against an eloquent model instead of the SOQL connection model. However, i can't confirm that without seeing more of how your models are set up. Part of me wonders if the closure query could be the issue. i'm surprised it hasn't come up yet if thats the case.

@Engveloper
Copy link
Author

Hi @roblesterjr04, thank you for reply. Both models (Organization and Affiliation) extends from the Lester\EloquentSalesForce\Model class, and this is the relation definition inside the organization model:

public function affiliations(): SOQLHasMany
{
    return $this->hasMany(Affiliation::class, 'npe5__Organization__c', 'Id');
}

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

2 participants