Slide 23
Slide 23 text
Solution: enforced: and change_foreign_key
# For migrations
class AddArticlesForeignKey < ActiveRecord::Migration[8.2]
def change
add_foreign_key :comments, :articles, enforced: false
end
end
# For general use, e.g. application code
connection.change_foreign_key :comments, :posts, enforced: false
connection.change_foreign_key :comments, :posts, enforced: true
Public API for applications too, not just for fixtures (rails/rails#57377)
23