@@ -520,6 +520,8 @@ def compute_class(name)
520
520
521
521
def initialize ( name , scope , options , active_record )
522
522
super
523
+
524
+ @validated = false
523
525
@type = -( options [ :foreign_type ] &.to_s || "#{ options [ :as ] } _type" ) if options [ :as ]
524
526
@foreign_type = -( options [ :foreign_type ] &.to_s || "#{ name } _type" ) if options [ :polymorphic ]
525
527
@join_table = nil
@@ -620,6 +622,8 @@ def join_foreign_key
620
622
end
621
623
622
624
def check_validity!
625
+ return if @validated
626
+
623
627
check_validity_of_inverse!
624
628
625
629
if !polymorphic? && ( klass . composite_primary_key? || active_record . composite_primary_key? )
@@ -629,6 +633,8 @@ def check_validity!
629
633
raise CompositePrimaryKeyMismatchError . new ( self )
630
634
end
631
635
end
636
+
637
+ @validated = true
632
638
end
633
639
634
640
def check_eager_loadable!
@@ -979,6 +985,8 @@ class ThroughReflection < AbstractReflection # :nodoc:
979
985
980
986
def initialize ( delegate_reflection )
981
987
super ( )
988
+
989
+ @validated = false
982
990
@delegate_reflection = delegate_reflection
983
991
@klass = delegate_reflection . options [ :anonymous_class ]
984
992
@source_reflection_name = delegate_reflection . options [ :source ]
@@ -1142,6 +1150,8 @@ def through_options
1142
1150
end
1143
1151
1144
1152
def check_validity!
1153
+ return if @validated
1154
+
1145
1155
if through_reflection . nil?
1146
1156
raise HasManyThroughAssociationNotFoundError . new ( active_record , self )
1147
1157
end
@@ -1179,6 +1189,8 @@ def check_validity!
1179
1189
end
1180
1190
1181
1191
check_validity_of_inverse!
1192
+
1193
+ @validated = true
1182
1194
end
1183
1195
1184
1196
def constraints
0 commit comments