這可能是我需要使用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