Reputation: 4898
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: SELECT
ch_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?
Upvotes: 0
Views: 278
Reputation: 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.
Upvotes: 1