Skip to content

v0.4.1: @context never set for JSONAPI::FindOperation.record_count #263

@realityendshere

Description

@realityendshere

The record_count method seen below references @context, but that attribute does not appear to be set anywhere. As a result, trying to narrow results with a custom self.records in a resource results in a variety of nil-does-not-have-that-method style errors.

https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/operation.rb#L26-L30

def record_count
  @_record_count ||= @resource_klass.find_count(@resource_klass.verify_filters(@filters, @context),
                                                     context: @context,
                                                     include_directives: @include_directives)
end

This seems to impact top level links and pagination totals.

As a quick patch, I set @context in a patch included in an initializer:

module JSONAPIFindOperationPatch
  def apply(context)
    @context = context
    super
  end
end

module JSONAPI
  class FindOperation
    prepend JSONAPIFindOperationPatch
  end
end

v0.4.0 does not appear to to have this issue with misplaced context. If I am missing something obvious, let me know!

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