Skip to content

How do I use getResourceKey() on Relationship? #177

Description

@wukongrita

Hi @flugg ,

I have setup my models with getResourcKey() for both models:

NelitiVolume.php

. . .
    public function getResourceKey(): string {
        return 'neliti-volumes';
    }
. . .

NelitiPublication.php

. . .
    public function getResourceKey(): string {
        return 'neliti-publications';
    }
. . .

When I try to get the result from the url using /neliti-volumes?include=neliti-publication, I get the type is using camel-case; not using the kebab-case that I already defined in the models:

{
  "data": [
    {
      "type": "neliti-volumes",
      "id": "088f4670-8993-4ffc-86e4-58036442cebe",
      "attributes": {
        "volume": "BB",
        "number": "3",
      },
      "relationships": {
        "neliti-publication": { // this one is from the url that mapped with the transformers
          "data": {
            "type": "nelitiPublication", // this one should be neliti-publications that get from getResourceKey()
            "id": "39676c75-6e03-11ea-9660-ed7fb61131c5"
          }
        }
      }
    },
    . . .
  ]
}

Btw, I am using JSON API Serializer from PHP League...

Did I miss something?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions