Rails で 1 対多の関連付けを設定しましたが、外部キーが正しく設定されていないためにテストが失敗し続けます。誰かアドバイスがあればと思いました。
rota と user の 2 つのモデルがあります。ユーザーが勤務表を「作成」してほしい。ユーザーは複数の勤務表を作成できます。
テスト失敗
*rota_spec:*
it {should belong_to :creator}
Expected Rota to have a belongs_to association called creator (Rota does not have a creator_id foreign key.)
*user_spec:*
it {should have_many :created_rotas}
Expected User to have a has_many association called created_rotas (Rota does not have a creator_id foreign key.)
Rota.rb
belongs_to :creator, :class_name => "User"
ユーザー.rb
has_many :created_rotas, :class_name => "Rota", :foreign_key => "creator_id"
移行
class AddCreatorToRotas < ActiveRecord::Migration
def change
add_column :rotas, :creator_id, :string
end
end