relationship manager on belongs to many with pivot model throws error

I have a following relation on Project::model
public function Members(): BelongsToMany
{
return $this->belongsToMany(Member::class)
->withPivot('responsibility_id')
->using(ProjectMember::class)
->with('pivot.responsibility')
->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
->orderByPivot('responsibilities.order')
->withTimestamps();
}
public function Members(): BelongsToMany
{
return $this->belongsToMany(Member::class)
->withPivot('responsibility_id')
->using(ProjectMember::class)
->with('pivot.responsibility')
->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
->orderByPivot('responsibilities.order')
->withTimestamps();
}
when I try to use relation manager I am getting Call to a member function newCollection() on null error note that the relationship manager works OK if Member data only from pivot table is gathered (when I comment out pivot additions/ relations)
public function Members(): BelongsToMany
{
return $this->belongsToMany(Member::class)
->withPivot('responsibility_id')
// ->using(ProjectMember::class)
// ->with('pivot.responsibility')
// ->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
// ->orderByPivot('responsibilities.order')
->withTimestamps();
}
public function Members(): BelongsToMany
{
return $this->belongsToMany(Member::class)
->withPivot('responsibility_id')
// ->using(ProjectMember::class)
// ->with('pivot.responsibility')
// ->leftJoin('responsibilities', 'project_member.responsibility_id', '=', 'responsibilities.id')
// ->orderByPivot('responsibilities.order')
->withTimestamps();
}
1 Reply
dascorp
dascorpOP2y ago
I believe ->with('pivot.responsibility') breaks the table and causes the error.
Want results from more Discord servers?
Add your server