766
767
768
769
770
771
772
773
774
775
776
777
778
|
# File 'activerecord/lib/active_record/reflection.rb', line 766
def klass
@klass ||= delegate_reflection.compute_class(class_name).tap do |klass|
if !parent_reflection.is_a?(HasAndBelongsToManyReflection) &&
!(klass.reflections.key?(options[:through].to_s) ||
klass.reflections.key?(options[:through].to_s.pluralize)) &&
active_record.type_for_attribute(active_record.primary_key).type != :integer
raise NotImplementedError, <<~MSG.squish
In order to correctly type cast #{active_record}.#{active_record.primary_key},
#{klass} needs to define a :#{options[:through]} association.
MSG
end
end
end
|