diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2017-07-25 07:51:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-25 07:51:20 -0400 |
commit | ec21b97214e1ca415030be1a0d0d6f4ff33b283c (patch) | |
tree | 31874c2c3d8c903847d020a58a6b4ccba7c05440 /activerecord | |
parent | 1d3b6d23109157b794baca09a9d1167fa40a58fe (diff) | |
parent | 75ccdfed8d43d79f6590653212ecea7124759439 (diff) | |
download | rails-ec21b97214e1ca415030be1a0d0d6f4ff33b283c.tar.gz rails-ec21b97214e1ca415030be1a0d0d6f4ff33b283c.tar.bz2 rails-ec21b97214e1ca415030be1a0d0d6f4ff33b283c.zip |
Merge pull request #29916 from lugray/stop_generating_application_record
Stop creating ApplicationRecord on model generation
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/application_record/application_record_generator.rb | 26 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/application_record/templates/application_record.rb (renamed from activerecord/lib/rails/generators/active_record/model/templates/application_record.rb) | 0 | ||||
-rw-r--r-- | activerecord/lib/rails/generators/active_record/model/model_generator.rb | 23 |
4 files changed, 31 insertions, 23 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index afc459ef68..a656c767c0 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* ApplicationRecord is no longer generated when generating models. If you + need to generate it, it can be created with `rails g application_record`. + + *Lisa Ugray* + * Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list. *Ryuta Kamizono* diff --git a/activerecord/lib/rails/generators/active_record/application_record/application_record_generator.rb b/activerecord/lib/rails/generators/active_record/application_record/application_record_generator.rb new file mode 100644 index 0000000000..d18330f5b2 --- /dev/null +++ b/activerecord/lib/rails/generators/active_record/application_record/application_record_generator.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "rails/generators/active_record" + +module ActiveRecord + module Generators # :nodoc: + class ApplicationRecordGenerator < ::Rails::Generators::Base # :nodoc: + source_root File.expand_path("templates", __dir__) + + # FIXME: Change this file to a symlink once RubyGems 2.5.0 is required. + def create_application_record + template "application_record.rb", application_record_file_name + end + + private + + def application_record_file_name + @application_record_file_name ||= if namespaced? + "app/models/#{namespaced_path}/application_record.rb" + else + "app/models/application_record.rb" + end + end + end + end +end diff --git a/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb b/activerecord/lib/rails/generators/active_record/application_record/templates/application_record.rb index 60050e0bf8..60050e0bf8 100644 --- a/activerecord/lib/rails/generators/active_record/model/templates/application_record.rb +++ b/activerecord/lib/rails/generators/active_record/application_record/templates/application_record.rb diff --git a/activerecord/lib/rails/generators/active_record/model/model_generator.rb b/activerecord/lib/rails/generators/active_record/model/model_generator.rb index 7a1bb7efdc..25e54f3ac8 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -23,13 +23,11 @@ module ActiveRecord end def create_model_file - generate_application_record template "model.rb", File.join("app/models", class_path, "#{file_name}.rb") end def create_module_file return if regular_class_path.empty? - generate_application_record template "module.rb", File.join("app/models", "#{class_path.join('/')}.rb") if behavior == :invoke end @@ -41,31 +39,10 @@ module ActiveRecord attributes.select { |a| !a.reference? && a.has_index? } end - # FIXME: Change this file to a symlink once RubyGems 2.5.0 is required. - def generate_application_record - if behavior == :invoke && !application_record_exist? - template "application_record.rb", application_record_file_name - end - end - # Used by the migration template to determine the parent name of the model def parent_class_name options[:parent] || "ApplicationRecord" end - - def application_record_exist? - file_exist = nil - in_root { file_exist = File.exist?(application_record_file_name) } - file_exist - end - - def application_record_file_name - @application_record_file_name ||= if mountable_engine? - "app/models/#{namespaced_path}/application_record.rb" - else - "app/models/application_record.rb" - end - end end end end |