@@ -416,6 +416,9 @@ def mapping
416
416
# Active Record class.
417
417
class AssociationReflection < MacroReflection #:nodoc:
418
418
def compute_class ( name )
419
+ if polymorphic?
420
+ raise ArgumentError , "Polymorphic association does not support to compute class."
421
+ end
419
422
active_record . send ( :compute_type , name )
420
423
end
421
424
@@ -608,13 +611,7 @@ def automatic_inverse_of
608
611
if can_find_inverse_of_automatically? ( self )
609
612
inverse_name = ActiveSupport ::Inflector . underscore ( options [ :as ] || active_record . name . demodulize ) . to_sym
610
613
611
- begin
612
- reflection = klass . _reflect_on_association ( inverse_name )
613
- rescue NameError
614
- # Give up: we couldn't compute the klass type so we won't be able
615
- # to find any associations either.
616
- reflection = false
617
- end
614
+ reflection = klass . _reflect_on_association ( inverse_name )
618
615
619
616
if valid_inverse_reflection? ( reflection )
620
617
return inverse_name
@@ -626,9 +623,6 @@ def automatic_inverse_of
626
623
# +automatic_inverse_of+ method is a valid reflection. We must
627
624
# make sure that the reflection's active_record name matches up
628
625
# with the current reflection's klass name.
629
- #
630
- # Note: klass will always be valid because when there's a NameError
631
- # from calling +klass+, +reflection+ will already be set to false.
632
626
def valid_inverse_reflection? ( reflection )
633
627
reflection &&
634
628
klass <= reflection . active_record &&
@@ -732,6 +726,9 @@ def join_foreign_key
732
726
end
733
727
734
728
private
729
+ def can_find_inverse_of_automatically? ( _ )
730
+ !polymorphic? && super
731
+ end
735
732
736
733
def calculate_constructable ( macro , options )
737
734
!polymorphic?
0 commit comments