public function invitation(): hasOne
{
return $this->hasOne(Invitation::class)->where([
['user_id', $this->user_id],
['survey_id', $this->survey_id]
]);
}
which returns :
local.ERROR: SQLSTATE[42703]: Undefined column: 7 ERROR: column invitations.participation_id does not exist
Participation and Invitation models both have user_id and survey_id, and there's always a participation for an invitation. How can I change this code to get the invitation corresponding to a participation, and be able to load like this ->with('invitation') ?
With a has one relationship, Laravel is looking for a participation_id field in the invitations table. It seems that the invitations table doesn't have any participation_id field.
Or perhaps you have named it differently ? If yes, you need to specify its name within the relationship definition.