【发布时间】:2020-01-29 00:55:19
【问题描述】:
我发现将一个关系表绑定到我的第二个数据库有些困难。
在“db_main”中,我有表格,其中包含每个对象的基本详细信息,而不是其他表格:“db_site1”、“db_site2”等,在这些表格中我保存了有关相同对象的详细信息。
一切都在使用该架构找到,除了我有关系表(bookmaker_games)的一种情况,它必须只在“db_main”上。该表保存了博彩公司和游戏之间的关系。
在我的网站1上,我想列出以下型号的博彩公司的游戏:
class Bookmaker extends Model {
public function games() {
// here the database is "db_site1"
return $this->belongsToMany('App\Models\Game', 'bookmaker_games', 'bookmaker_id', 'game_id');
}
}
class Game extends Model {
public function bookmakers() {
// here the database is "db_site1"
return $this->belongsToMany('App\Models\Bookmaker', 'bookmaker_games', 'game_id', 'bookmaker_id');
}
}
class BookmakerGame extends Model {
protected $connection = 'db_main';
}
当我尝试返回所有游戏时,它认为“bookmaker_games”-table 在数据库“db_site1”上,这是错误的。
告诉该关系查看正确数据库的最佳方法是什么?
【问题讨论】:
-
类
BookmakerGame应该扩展Illuminate\Database\Eloquent\Relations\Pivot -
我试过了,但还是出现同样的错误:SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_site1.bookmaker_games' doesn't exis
标签: laravel eloquent relationship