Skip to content

Commit 9c0391d

Browse files
committed
Clarify logic for processing polymorphic path segments with resource type
1 parent 6243176 commit 9c0391d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/jsonapi/active_relation_resource_finder/join_tree.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ def process_path_to_tree(path_segments, resource_klass, default_join_type, defau
8383

8484
segment.relationship.resource_types.each do |related_resource_type|
8585
related_resource_klass = resource_klass.resource_klass_for(related_resource_type)
86-
if !segment.path_specified_resource_klass? || related_resource_klass == segment.resource_klass
86+
87+
# If the resource type was specified in the path segment we want to only process the next segments for
88+
# that resource type, otherwise process for all
89+
process_all_types = !segment.path_specified_resource_klass?
90+
91+
if process_all_types || related_resource_klass == segment.resource_klass
8792
related_resource_tree = process_path_to_tree(path_segments.dup, related_resource_klass, default_join_type, default_polymorphic_join_type)
8893
node[:resource_klasses][resource_klass][:relationships][segment.relationship].deep_merge!(related_resource_tree)
8994
end

0 commit comments

Comments
 (0)