aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2016-01-31 22:51:36 +0900
committeryui-knk <spiketeika@gmail.com>2016-01-31 22:51:36 +0900
commit7e4b2abeeeae10a734793f284cfec9f9ca4b166e (patch)
tree512b61c3e94c254b436ba9c7d286d5748b451c0c /activerecord/lib
parent8dfb8760489abbf038d48e230e32c681b408ebfa (diff)
downloadrails-7e4b2abeeeae10a734793f284cfec9f9ca4b166e.tar.gz
rails-7e4b2abeeeae10a734793f284cfec9f9ca4b166e.tar.bz2
rails-7e4b2abeeeae10a734793f284cfec9f9ca4b166e.zip
Each concrete classes have responsibility to return `association_class`
Diffstat (limited to 'activerecord/lib')
-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)