0
我有以下表格。如何更改連接表上的外鍵?
class Reward ActiveRecord::Base
has_many :earned_rewards
has_many :players, :through => :earned_rewards
end
class EarnedReward < ActiveRecord::Base
belongs_to :reward
belongs_to :player
end
class Player < ActiveRecord::Base
has_many :earned_rewards
has_many :rewards, :through => :earned_rewards
end
我的問題是EarnedReward表上的外鍵是字符串類型,並且不符合Rails約定。我希望將Integer字段(player_id和reward_id)添加到EarnedReward表中以充當新的外鍵,同時保留舊字段及其值。
我正在使用Rails 4.1.1,我不確定如何完成此操作。
什麼是當前的外鍵? – 2014-09-13 01:57:42