Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyFormat breaks included relationships #119

Open
juni0r opened this issue Oct 23, 2020 · 0 comments
Open

KeyFormat breaks included relationships #119

juni0r opened this issue Oct 23, 2020 · 0 comments

Comments

@juni0r
Copy link

juni0r commented Oct 23, 2020

KeyFormat breaks included relationships when the relationship's name is subject to key transformation.

class Resource < JSONAPI::Serializable::Resource
  extend JSONAPI::Serializable::Resource::KeyFormat
  key_format ->(key) { key.to_s.camelize(:lower) }
end
class ContactResource < Resource
  type 'contacts'

  has_many :contact_groups

  attributes :first_name, :last_name, :email # , ...
end
class ContactGroupResource < Resource
  type 'contactGroups'

  attributes :name
end

Results in the relationship key to be transformed but related resources don't get included:

{
  "id": "046ffaf3-9c7b-4f36-a33b-1948cb889200",
  "type": "contacts",
  "attributes": {
    "firstName": "John",
    "lastName": "Doe",
    "email": '[email protected]'
  },
  "relationships": {
   "contactGroups": {
      "meta": {
        "included": false
      }
    }
  }
}

Without using KeyFormat it works as expected:

{
  "id": "046ffaf3-9c7b-4f36-a33b-1948cb889200",
  "type": "contacts",
  "attributes": {
    "first_name": "John",
    "last_name": "Doe",
    "email": '[email protected]',
  },
  "relationships": {
    "contact_groups": {
      "data": [
        {
          "type": "contactGroups",
          "id": "c88e3a19-f814-49d9-a458-40c2103f0003"
        }
      ]
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant