has_and_belongs_to 外部数据库连接
这可能是我需要使用 has_many :through 的情况,但我不想这样做,因为这是一个没有属性情况的简单连接表。
我的提供者表位于外部数据库中:
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: 表 “chshared.dashboards_providers”不存在:SELECT
ch_cdn
.* FROMch_cdn
内连接dashboards_providers
ONch_cdn
.cdn_id
=dashboards_providers
.provider_id
地点dashboards_providers
。dashboard_id
= 1
它在错误的数据库中查找连接表。是否可以指定“仪表板”提供程序位于另一个数据库中?
This may be a case where I need to use has_many :through, but I'd prefer not to as this is a simple join table without attributes case.
My provider table is in an external database:
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
But when I try:
Dashboard.first.providers << Provider.first
I get
ActiveRecord::StatementInvalid: Mysql2::Error: Table
'chshared.dashboards_providers' doesn't exist: SELECTch_cdn
.* FROMch_cdn
INNER JOINdashboards_providers
ONch_cdn
.cdn_id
=dashboards_providers
.provider_id
WHEREdashboards_providers
.dashboard_id
= 1
It's looking in the wrong database for the join table. Is it possible to specify that 'dashboards' providers lives in the other database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个错字,但是看看“Class Dashboard”,应该是“class Dashboard”。另外,这是从 11 月份回来的,所以我认为你已经解决了它。
This might be a typo, but look at "Class Dashboard", should be "class Dashboard". Plus this is back from Nov. so I think you already solved it.