vendredi 25 janvier 2019

Laravel 5.7 - eager loading a relationship's relationship

How does one go about this? I tried this:

return $this->hasMany(ResolutionLog::class, 'ant_id', 'id')->with('resolutionStatus');

and got the error:

Call to undefined relationship [resolutionLog] on model [App\Models\ResolutionLog].

Or in tinker I'm getting this error when get a resolutionLog collection and attempt to access the resolutionStatus relationship:

LogicException with message 'App/Models/ResolutionLog::resolutionStatus must return a relationship instance.'

Here is the resolutionStatus relationship on the ResolutionLog model:

public function resolutionStatus()
{
    $this->hasOne(ResolutionStatus::class, 'id', 'resolution_status_id');
}

And the resolutionLog relationship on the ResolutionStatus model:

public function resolutionLog()
{
    return $this->hasMany(ResolutionLog::class, 'resolution_status_id', 'id');
}

It should be a one->many relationship between a ResolutionLog has one ResolutionStatus. A ResolutionStatus can have many ResolutionLogs.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire