I am trying to implement the HATBM association between the two models of which one model points to my local database table and other model is pointing to the table of an external database.
local model :
class Group < ApplicationRecord
has_and_belongs_to_many :chains
end
Model connecting to an external database :
class Chain < ApplicationRecord
establish_connection :xyz
self.table_name = 'queues'
has_and_belongs_to_many :groups
end
Join table(chains_groups) fields:
1) :group_id
2) :chain_id
Application details:
Rails : 5.2.0
Database : postgresql
Whenever I try to insert data in join table I am getting an error ActiveRecord::StatementInvalid stating that chains_groups table doesn't exist. It seems like that, it is always searching for the join table (chains_groups) on external database which is present in my local database. I even try to implement "has_many :through" association but the result is the same.