From 529b4d2a982268ba621bb04fc41f30775ba5d812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 15 Apr 2024 15:21:56 +0200 Subject: [PATCH] Don't validate foreign key in required belongs_to Before this change, every time we saved a record, the association was validated if we had `belongs_to :something, required: true`. After this change [1], it's only validated if the `something_id` column is nil (or `something_type` for polymorphic associations) or if the `something_id` attribute has changed. The main difference is that we no longer get validation errors if the associated record has been deleted. Doesn't affect us much, so we're going with the new default value. [1] Pull request 46522 in https://github.com/rails/rails --- config/initializers/new_framework_defaults_7_1.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/new_framework_defaults_7_1.rb b/config/initializers/new_framework_defaults_7_1.rb index 473525c47..9c52f5dfc 100644 --- a/config/initializers/new_framework_defaults_7_1.rb +++ b/config/initializers/new_framework_defaults_7_1.rb @@ -165,7 +165,7 @@ Rails.application.config.active_record.raise_on_assign_to_attr_readonly = true # The previous behavior was to validate the presence of the parent record, which performed an extra query # to get the parent every time the child record was updated, even when parent has not changed. #++ -# Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false +Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false ### # Enable precompilation of `config.filter_parameters`. Precompilation can