Answers for "rails destroy cascade"

0

rails on_delete cascade not working

// dont do a foreing_key, instead use t.references
class CreateDocumentImages < ActiveRecord::Migration[5.1]
  def change
    create_table :document_images do |t|
      t.references :document, foreign_key: { on_delete: :cascade }
      t.references :image, foreign_key: { on_delete: :cascade}
      t.timestamps
    end
  end
end
Posted by: Guest on December-05-2020

Browse Popular Code Answers by Language