我有两个模型,如下所述。我有一个我想指定的连接表,但由于它们不在同一个数据库中,所以它出错了。如果我在“join_table:”选项哈希中指定我的开发数据库,那么它可以工作。但当然,这会在进入生产阶段时破裂。
错误
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
模型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
模型B
class Player < ActiveRecord::Base
has_and_belongs_to_many :player_extracts, join_table: "ncaa_matches", association_foreign_key: 'ncaa_id', uniq: true
end
答案 0 :(得分:0)
这似乎有效,但这是处理这个问题的正确方法吗?
has_and_belongs_to_many :player_extracts, join_table: Rails.configuration.database_configuration[Rails.env]["database"].to_s+".dbo.ncaa_matches", association_foreign_key: 'ncaa_id', uniq: true