【发布时间】:2018-02-02 13:15:00
【问题描述】:
Laravel 5.5
我有两个模型,User 和 Conversation
用户到对话是多对多关系(双向)。
我的表结构如下:
conversation is on database_1
conversation_user is on database_1
user is on database_2
在 App\Conversation.php 内:
protected $connection = 'database_1';
protected $table = 'conversations';
public function users()
{
return $this->belongsToMany("App\User");
}
App\User.php 内部:
protected $connection = 'database_2';
protected $table = 'users';
public function conversations()
{
return $this->belongsToMany("App\Conversation");
}
所有这些都在同一台服务器上,但有没有办法让它工作?
在 Conversation 上查询关系以获取用户时,它正在寻找 database_2.conversation_user 而不是 database_1.conversation_user
所以本质上,我需要说Pivot表位于database_1,有没有办法做到这一点?
【问题讨论】: