这可能是我需要使用has_many:through的一种情况,但我不希望这是因为这是一个没有属性大小的简单连接表。has_and_belongs_to外部数据库加入
我的供应商表是在外部数据库:
class Provider < ActiveRecord::Base
establish_connection :external_db
set_table_name :ch_cdn
set_primary_key :cdn_id
has_and_belongs_to_many :dashboards
end
Class Dashboard < ActiveRecord::Base
has_and_belongs_to_many :providers
end
但是当我尝试: Dashboard.first.providers < < Provider.first
我得到
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'chshared.dashboards_providers' doesn't exist: SELECT
ch_cdn
.* FROMch_cdn
INNER JOINdashboards_providers
ONch_cdn
.cdn_id
=dashboards_providers
.provider_id
WHEREdashboards_providers
.dashboard_id
= 1
这是查看连接表的错误数据库。是否可以指定“仪表板”提供程序位于另一个数据库中?
从来没有解决它,最终将表移动到共享数据库。 – oreoshake