diff options
author | Genadi Samokovarov <gsamokovarov@gmail.com> | 2016-04-27 18:30:17 +0300 |
---|---|---|
committer | Genadi Samokovarov <gsamokovarov@gmail.com> | 2016-04-28 10:12:06 +0300 |
commit | e6ed3aaf437887bc25a1f715f21c5ca3ebbc966f (patch) | |
tree | 8b24be4de8e045828209d724e1a6402028e4b907 /activerecord | |
parent | abff83e60e9d91975b4788ef9cca388ab2536c10 (diff) | |
download | rails-e6ed3aaf437887bc25a1f715f21c5ca3ebbc966f.tar.gz rails-e6ed3aaf437887bc25a1f715f21c5ca3ebbc966f.tar.bz2 rails-e6ed3aaf437887bc25a1f715f21c5ca3ebbc966f.zip |
Always genererate models with ApplicationRecord parent
Currently, if we generate a model while
`app/model/application_record.rb` isn't present, we'll end up with a
model with an `ActiveRecord::Base` parent _and_ a newly generated
`app/models/application_record.rb`.
While the behavior for choosing an `ActiveRecord::Base` was chosen for
an easier migration math to 5.0, generating the
`app/model/application_record.rb` file kinda contradicts with it.
In any case, I think we should decide on a behavior and stick to it.
Here, I'm changing the generated parent to always be `ApplicationRecord`
and to always create `app/model/application_record.rb` if it doesn't
exist.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/rails/generators/active_record/model/model_generator.rb | 14 |
1 files changed, 3 insertions, 11 deletions
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 f191eff5bf..0d72913258 100644 --- a/activerecord/lib/rails/generators/active_record/model/model_generator.rb +++ b/activerecord/lib/rails/generators/active_record/model/model_generator.rb @@ -21,14 +21,14 @@ module ActiveRecord end def create_model_file - template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") 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? - template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke generate_application_record + template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke end hook_for :test_framework @@ -48,7 +48,7 @@ module ActiveRecord # Used by the migration template to determine the parent name of the model def parent_class_name - options[:parent] || determine_default_parent_class + options[:parent] || 'ApplicationRecord' end def application_record_exist? @@ -64,14 +64,6 @@ module ActiveRecord 'app/models/application_record.rb' end end - - def determine_default_parent_class - if application_record_exist? - "ApplicationRecord" - else - "ActiveRecord::Base" - end - end end end end |