I have two models as outlined below. I have a joins table I want to specify, but it errors out since they're not in the same database. If I specify my development database in my "join_table:" options hash then it works. But of course that would break when moving up to production.
Error
TinyTds::Error: Invalid object name 'ncaa_matches'.: EXEC sp_executesql N'SELECT 1 AS one FROM [player_extracts] INNER JOIN [ncaa_matches] ON [player_extracts].[college_player_id] = [ncaa_matches].[ncaa_id] WHERE [ncaa_matches].[player_id] = @0 ORDER BY [player_extracts].[college_player_id] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', N'@0 int', @0 = 247489
Model A
class PlayerExtract < IncomingModel
self.table_name = 'player_extracts'
self.primary_key = 'player_id'
has_and_belongs_to_many :players, join_table: "ncaa_matches", association_foreign_key: 'player_id', uniq: true
end
Model B
class Player < ActiveRecord::Base
has_and_belongs_to_many :player_extracts, join_table: "ncaa_matches", association_foreign_key: 'ncaa_id', uniq: true
end