SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias on relationship

a 夏天 提交于 2019-12-01 15:34:28

Answered via the Larachat official Slack:

The relationship is missing a pivot table for this to work. The second argument in the participants method is the pivot table to use:

public function participants()
{
    return $this->belongsToMany('Namespace\Modules\Email\Models\Participant', 'PIVOT', 'message_id', 'user_id')->withTimestamps();
}

Therefore, you can't use participants as the pivot because it is one of the tables in the relationship, you need a message_participant pivot table.

Your error is

...from `participants` inner join `participants` ...

You need to provide aliases for each reference, as in

...from `participants` p1 inner join `participants` p2 ...

and then use p1 and p2 in the correct places, for example

...on p1.`id` = p2.`user_id` ...

(I'm guessing on which is p1 and which is p2; you have to make that determination)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!