所以,我从Laravel收到以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'participants' (SQL: select `participants`.*, `participants`.`message_id` as `pivot_message_id`, `participants`.`user_id` as `pivot_user_id`, `participants`.`created_at` as `pivot_created_at`, `participants`.`updated_at` as `pivot_updated_at` from `participants` inner join `participants` on `participants`.`id` = `participants`.`user_id` where `participants`.`deleted_at` is null and `participants`.`message_id` in (2))
Run Code Online (Sandbox Code Playgroud)
我的留言/参与者关系如下:
public function participants()
{
return $this->belongsToMany('Namespace\Modules\Email\Models\Participant', 'participants', 'message_id', 'user_id')->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)
而我试图这样称呼它:
public function getAllMessages()
{
return Message::with('user')->with('participants')->get();
}
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?到底是怎么回事?
编辑:包含完整模型
消息 类消息扩展Eloquent {使用PublishedTrait; 使用SoftDeletingTrait;
class Message extends Eloquent
{
use PublishedTrait;
use SoftDeletingTrait;
/**
* …Run Code Online (Sandbox Code Playgroud)