diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-04-19 17:47:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-19 17:47:39 +0200 |
commit | 1a5381ff0cf04af68a50bd04f265b9b8199e37b4 (patch) | |
tree | b238c978e750c81a836e9dfaf67a566d13b05c60 /railties/lib/rails | |
parent | 69fcaaaf15880dc20b9ec19a9b839f375a64a1d2 (diff) | |
parent | 8b4d344815655027d9f7584c0a59271dce8f1d5a (diff) | |
download | rails-1a5381ff0cf04af68a50bd04f265b9b8199e37b4.tar.gz rails-1a5381ff0cf04af68a50bd04f265b9b8199e37b4.tar.bz2 rails-1a5381ff0cf04af68a50bd04f265b9b8199e37b4.zip |
Merge pull request #36001 from prathamesh-sonpatki/null-false-default-belongs-to
Add `null: false` constraint by default for `belongs_to` associations
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 99c1bc4269..1a80e71eae 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/time" +require "active_support/deprecation" module Rails module Generators @@ -51,6 +52,12 @@ module Rails type = $1 provided_options = $2.split(/[,.-]/) options = Hash[provided_options.map { |opt| [opt.to_sym, true] }] + + if options[:required] + ActiveSupport::Deprecation.warn("Passing {required} option has no effect on the model generator. It will be removed in Rails 6.1.\n") + options.delete(:required) + end + return type, options else return type, {} @@ -137,7 +144,7 @@ module Rails end def required? - attr_options[:required] + reference? && Rails.application.config.active_record.belongs_to_required_by_default end def has_index? @@ -183,7 +190,6 @@ module Rails def options_for_migration @attr_options.dup.tap do |options| if required? - options.delete(:required) options[:null] = false end |