aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2016-01-31 20:51:49 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2016-01-31 20:51:49 +0100
commit662889cf3621a9d536ec4a7e876c510b0ac3f946 (patch)
treeab2fef1c9a14d914e18ff8846372d2a4d23add1a /activerecord/lib/active_record
parent93abf58787396661230f31c7a2f58c18f30dbec9 (diff)
parent7e4b2abeeeae10a734793f284cfec9f9ca4b166e (diff)
downloadrails-662889cf3621a9d536ec4a7e876c510b0ac3f946.tar.gz
rails-662889cf3621a9d536ec4a7e876c510b0ac3f946.tar.bz2
rails-662889cf3621a9d536ec4a7e876c510b0ac3f946.zip
Merge pull request #23379 from yui-knk/define_association_class_on_each_concrete_class
Each concrete classes have responsibility to return `association_class`
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/reflection.rb47
1 files changed, 25 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 320ced5afa..cbb5b99a05 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -483,28 +483,7 @@ module ActiveRecord
# Returns +true+ if +self+ is a +has_one+ reflection.
def has_one?; false; end
- def association_class
- case macro
- when :belongs_to
- if polymorphic?
- Associations::BelongsToPolymorphicAssociation
- else
- Associations::BelongsToAssociation
- end
- when :has_many
- if options[:through]
- Associations::HasManyThroughAssociation
- else
- Associations::HasManyAssociation
- end
- when :has_one
- if options[:through]
- Associations::HasOneThroughAssociation
- else
- Associations::HasOneAssociation
- end
- end
- end
+ def association_class; raise NotImplementedError; end
def polymorphic?
options[:polymorphic]
@@ -629,6 +608,14 @@ module ActiveRecord
def macro; :has_many; end
def collection?; true; end
+
+ def association_class
+ if options[:through]
+ Associations::HasManyThroughAssociation
+ else
+ Associations::HasManyAssociation
+ end
+ end
end
class HasOneReflection < AssociationReflection # :nodoc:
@@ -639,6 +626,14 @@ module ActiveRecord
def macro; :has_one; end
def has_one?; true; end
+
+ def association_class
+ if options[:through]
+ Associations::HasOneThroughAssociation
+ else
+ Associations::HasOneAssociation
+ end
+ end
end
class BelongsToReflection < AssociationReflection # :nodoc:
@@ -650,6 +645,14 @@ module ActiveRecord
def belongs_to?; true; end
+ def association_class
+ if polymorphic?
+ Associations::BelongsToPolymorphicAssociation
+ else
+ Associations::BelongsToAssociation
+ end
+ end
+
def join_keys(association_klass)
key = polymorphic? ? association_primary_key(association_klass) : association_primary_key
JoinKeys.new(key, foreign_key)