こうかな。
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
で、こう。
class Status < ApplicationRecord
self.primary_key = :status_id
end
class Account < ApplicationRecord
self.primary_key = :account_id
end