rails g model session user:references
class CreateSessions < ActiveRecord::Migration[6.1]
def change
create_table :sessions do |t|
t.references :user, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateSessions < ActiveRecord::Migration[6.1]
def change
create_table :sessions do |t|
t.references :user, null: false, foreign_key: { on_delete: :cascade }
t.timestamps
end
end
end
https://api.rubyonrails.org/v7.0.1/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_foreign_key-label-Creating+a+cascading+foreign+key
Does this prevent the
after_destroy
callback from firing on theSession
model?