diff --git a/lib/mongoid/criteria/includable.rb b/lib/mongoid/criteria/includable.rb index 08edbfdbb14..89288351578 100644 --- a/lib/mongoid/criteria/includable.rb +++ b/lib/mongoid/criteria/includable.rb @@ -77,7 +77,7 @@ def inclusions=(value) # # @since 5.1.0 def add_inclusion(_klass, relation) - metadata = get_inclusion_metadata(_klass, relation) + metadata = _klass.reflect_on_association(relation) raise Errors::InvalidIncludes.new(_klass, [ relation ]) unless metadata inclusions.push(metadata) unless inclusions.include?(metadata) end @@ -116,7 +116,7 @@ def extract_nested_inclusion(_klass, relation) if _inclusion.is_a?(Array) extract_relations_list(association, _inclusion) else - add_inclusion(association, _inclusion) + add_inclusion(_klass.reflect_on_association(association).klass, _inclusion) end end end