diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-28 03:07:56 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-04 02:34:00 +0900 |
commit | d35875b7a3f559155a9378cbe9203b0b8ea580f9 (patch) | |
tree | e8d8c225cf2309976327a94370f09f901023a9b1 /activerecord/lib/active_record/associations | |
parent | 75a24602edacd3e66b5c38c2b5efe885dfdd14ab (diff) | |
download | rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.tar.gz rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.tar.bz2 rails-d35875b7a3f559155a9378cbe9203b0b8ea580f9.zip |
Extract all `base_class.name` as `polymorphic_name`
This is an alternative of #29722, and follow up of #32048.
This does not change the current behavior, but makes it easier to modify
all polymorphic names consistently.
Diffstat (limited to 'activerecord/lib/active_record/associations')
4 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 364f1fe74f..ca8c7794e0 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -201,8 +201,8 @@ module ActiveRecord if (reflection.has_one? || reflection.collection?) && !options[:through] attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key] - if reflection.options[:as] - attributes[reflection.type] = owner.class.base_class.name + if reflection.type + attributes[reflection.type] = owner.class.polymorphic_name end end diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index ad41ec8d2f..0a90a6104a 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -35,12 +35,12 @@ module ActiveRecord binds << last_reflection.join_id_for(owner) if last_reflection.type - binds << owner.class.base_class.name + binds << owner.class.polymorphic_name end chain.each_cons(2).each do |reflection, next_reflection| if reflection.type - binds << next_reflection.klass.base_class.name + binds << next_reflection.klass.polymorphic_name end end binds @@ -63,7 +63,7 @@ module ActiveRecord scope = apply_scope(scope, table, key, value) if reflection.type - polymorphic_type = transform_value(owner.class.base_class.name) + polymorphic_type = transform_value(owner.class.polymorphic_name) scope = apply_scope(scope, table, reflection.type, polymorphic_type) end @@ -84,7 +84,7 @@ module ActiveRecord constraint = table[key].eq(foreign_table[foreign_key]) if reflection.type - value = transform_value(next_reflection.klass.base_class.name) + value = transform_value(next_reflection.klass.polymorphic_name) scope = apply_scope(scope, table, reflection.type, value) end diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb index 55d789c66a..75b4c4481a 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -13,7 +13,7 @@ module ActiveRecord def replace_keys(record) super - owner[reflection.foreign_type] = record ? record.class.base_class.name : nil + owner[reflection.foreign_type] = record ? record.class.polymorphic_name : nil end def different_target?(record) diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 71c8f6df58..0f38d6bbda 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -117,7 +117,7 @@ module ActiveRecord scope = klass.scope_for_association if reflection.type - scope.where!(reflection.type => model.base_class.name) + scope.where!(reflection.type => model.polymorphic_name) end scope.merge!(reflection_scope) if reflection.scope |