Option for Cascade Delete for References or On Delete

This should work

create_table :childs do |t|
  t.references :parent, index: true, foreign_key: {on_delete: :cascade}
  t.string :name

  t.timestamps null: false
end

According to ActiveRecord::ConnectionAdapters::TableDefinition#references, if a hash is specified on the foreign_key option, it is directly passed down into the foreign_key method.

source:

foreign_key(col.to_s.pluralize, foreign_key_options.is_a?(Hash) ? foreign_key_options : {}) if foreign_key_options

Leave a Comment