Skip to content

UUIDResource has_many IdResource causes undefined method [] when doing GET [...]?includes= #1156

@butchmarshall

Description

@butchmarshall

This issue is a (choose one):

  • Problem/bug report.

Description

I've tracked the issue to lib/jsonapi/processor.rb:587.

resource_set[resource_klass] is holding the associated resources in an array key'd by a string {"1" => [...]} and attempting to access it via an int resource.id.

With the following resources just issue this get request (make sure to have include=).

GET /uuids/3bbaf722-4583-4fa6-ac36-9190d4b93f80?include=ids

class UuidResource < JSONAPI::Resource
  key_type :uuid
  has_many :ids
end

class IdResource < JSONAPI::Resource
  has_one :uuid
end

Throws error:

Internal Server Error: undefined method `[]' for nil:NilClass /var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:587:in `block (2 levels) in populate_resource_set'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:586:in `each'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:586:in `block in populate_resource_set'
/var/lib/gems/2.3.0/bundler/gems/jsonapi-resources-d185ebb76cd2/lib/jsonapi/processor.rb:542:in `each_key'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions