What
In find_related_polymorphic_fragments, polymorphic include field offsets are looked up with row[2].downcase.pluralize, but relation_positions is keyed by underscored resource types (e.g. assignment_templates). Multi-word model names never match, so the include crashes.
Expected Behavior
Polymorphic belongs_to includes succeed for all concrete types, including multi-word model names such as AssignmentTemplate.
Actual Behavior
For "AssignmentTemplate", lookup becomes "assignmenttemplates" instead of "assignment_templates". relation_positions[...] returns nil, then:
undefined method '[]' for nil
Single-word types (Assignment, Book) work only because downcase.pluralize and underscore.pluralize happen to match.
Steps to Reproduce, Screenshots
Define a polymorphic belongs_to whose polymorphic_types include a multi-word model (e.g. assignments and assignment_templates).
Persist a related record with configurable_type / equivalent = "AssignmentTemplate".
Request the parent with ?include=<polymorphic_relationship>.
Observe 500 / NoMethodError in find_related_polymorphic_fragments.
Affected line in v26.1.3:
relation_position = relation_positions[row[2].downcase.pluralize]
Upstream jsonapi-resources 0.10.x uses:
relation_position = relation_positions[row[2].underscore.pluralize]
Why
resource_types / join aliases follow ActiveSupport underscoring (AssignmentTemplate → assignment_templates). The pluck-row lookup must use the same inflection, or multi-word polymorphic types are unreachable. Aligning with upstream (underscore.pluralize) restores correct behavior for all STI/polymorphic class names.
Ref
Repo/tag: speee/jsonapi-resources v26.1.3
File: lib/jsonapi/active_relation_resource.rb (find_related_polymorphic_fragments)
Upstream 0.10.x equivalent uses underscore.pluralize on the same lookup
Suggested fix: one-line change downcase → underscore
Thank you for forking and updating this gem!
What
In find_related_polymorphic_fragments, polymorphic include field offsets are looked up with row[2].downcase.pluralize, but relation_positions is keyed by underscored resource types (e.g. assignment_templates). Multi-word model names never match, so the include crashes.
Expected Behavior
Polymorphic belongs_to includes succeed for all concrete types, including multi-word model names such as AssignmentTemplate.
Actual Behavior
For "AssignmentTemplate", lookup becomes "assignmenttemplates" instead of "assignment_templates". relation_positions[...] returns nil, then:
undefined method '[]' for nil
Single-word types (Assignment, Book) work only because downcase.pluralize and underscore.pluralize happen to match.
Steps to Reproduce, Screenshots
Define a polymorphic belongs_to whose polymorphic_types include a multi-word model (e.g. assignments and assignment_templates).
Persist a related record with configurable_type / equivalent = "AssignmentTemplate".
Request the parent with ?include=<polymorphic_relationship>.
Observe 500 / NoMethodError in find_related_polymorphic_fragments.
Affected line in v26.1.3:
relation_position = relation_positions[row[2].downcase.pluralize]
Upstream jsonapi-resources 0.10.x uses:
relation_position = relation_positions[row[2].underscore.pluralize]
Why
resource_types / join aliases follow ActiveSupport underscoring (AssignmentTemplate → assignment_templates). The pluck-row lookup must use the same inflection, or multi-word polymorphic types are unreachable. Aligning with upstream (underscore.pluralize) restores correct behavior for all STI/polymorphic class names.
Ref
Repo/tag: speee/jsonapi-resources v26.1.3
File: lib/jsonapi/active_relation_resource.rb (find_related_polymorphic_fragments)
Upstream 0.10.x equivalent uses underscore.pluralize on the same lookup
Suggested fix: one-line change downcase → underscore
Thank you for forking and updating this gem!