diff options
author | Josef Šimánek <josef.simanek@gmail.com> | 2015-02-14 03:24:54 +0100 |
---|---|---|
committer | Josef Šimánek <josef.simanek@gmail.com> | 2015-02-21 23:03:10 +0100 |
commit | 6576f7354e50afb79881aaf3a6f50f4e81dfab70 (patch) | |
tree | 9f53674c07731b069c0890fb26ab3d64b4207e8b /railties/lib | |
parent | bab3c7c63deee86305d80e24c4ea1124c0ec27d1 (diff) | |
download | rails-6576f7354e50afb79881aaf3a6f50f4e81dfab70.tar.gz rails-6576f7354e50afb79881aaf3a6f50f4e81dfab70.tar.bz2 rails-6576f7354e50afb79881aaf3a6f50f4e81dfab70.zip |
Require `belongs_to` by default.
Deprecate `required` option in favor of `optional` for belongs_to.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 977f5a1c03..899b33e529 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -89,6 +89,7 @@ module Rails def config_when_updating cookie_serializer_config_exist = File.exist?('config/initializers/cookies_serializer.rb') callback_terminator_config_exist = File.exist?('config/initializers/callback_terminator.rb') + active_record_belongs_to_required_by_default_config_exist = File.exist?('config/initializers/active_record_belongs_to_required_by_default.rb') config @@ -99,6 +100,10 @@ module Rails unless cookie_serializer_config_exist gsub_file 'config/initializers/cookies_serializer.rb', /json/, 'marshal' end + + unless active_record_belongs_to_required_by_default_config_exist + remove_file 'config/initializers/active_record_belongs_to_required_by_default.rb' + end end def database_yml @@ -258,6 +263,12 @@ module Rails end end + def delete_active_record_initializers_skipping_active_record + if options[:skip_active_record] + remove_file 'config/initializers/active_record_belongs_to_required_by_default.rb' + end + end + def finish_template build(:leftovers) end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb new file mode 100644 index 0000000000..30c4f89792 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/active_record_belongs_to_required_by_default.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Require `belongs_to` associations by default. +Rails.application.config.active_record.belongs_to_required_by_default = true |