Skip to content

Fields filtering with include #1475

@brcebn

Description

@brcebn

Version 0.9.12

When using fields[events]=name + include=establishment the key relationships disappear from the response hash.

Basic association is events belongs_to establishment

Issue is coming from here:

# JSONAPI::ResourceSerializer#supplying_relationship_fields

def supplying_relationship_fields(resource_klass)
        @_supplying_relationship_fields.fetch resource_klass do
          relationships = Set.new(resource_klass._relationships.keys.map(&:to_sym))
          cur = resource_klass
          while cur != JSONAPI::Resource
            if @fields.has_key?(cur._type)
              # here... 
              # It always empty the Set
              #relationships &= @fields[cur._type]
              break
            end
            cur = cur.superclass
          end
          @_supplying_relationship_fields[resource_klass] = relationships
        end
      end

Commenting relationships &= @fields[cur._type] solves this issue. @DavidMikeSimon could you describe your mind here? I know it was a loooong time ago but your help might help to correctly fix this issue.

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