Railsの勉強で表題の件ができずに困っております。
ご教授いただけないでしょうか。
AuthenticationモデルとAuthenticationLogモデルを下記の通りに関連付けを行い、
AuthenticationLogモデルのauthentication_idをnilで生成する方法はないでしょうか。
AuthenticationLog.create(:key => "testkey", :authentication_id => nil)
でロールバックが発生して困っております。
①Authenticationモデルについて
class CreateAuthentications < ActiveRecord::Migration[5.0] def change create_table: authentications do |t| t.string :key t.timestamps end end end class Authentication < ApplicationRecord has_many :authentication_logs end
②AuthenticationLogモデルについて
class CreateAuthenticationLogs < ActiveRecord::Migration[5.0] def change create_table: authentication_logs do |t| t.string :key t.integer :authentication_id => こいつをnilでcreateしたい t.timestamps end end end class AuthenticationLog < ApplicationRecord belongs_to :authentication end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。