こうかな。
class CreateStatus < ActiveRecord::Migration[7.1]
def change
create_table :statuses, id: false do |t|
t.integer :status_id, null: false, primary_key: true
t.timestamps
end
add_foreign_key :statuses, :accounts, column: :account_id , primary_key: :account_id, on_delete: :cascade
end
end
class CreateAccount < ActiveRecord::Migration[7.1]
def change
create_table :accounts, id: false do |t|
t.integer :account_id, null: false, primary_key: true
t.timestamps
end
end
end
あ、Statusに t.references :account, null: false かいてないや。……まあそういう感じで。
class Status < ApplicationRecord
self.primary_key = :status_id
belongs_to :account, primary_key: :account_id
end
こっちはこうか。