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

Missing key_type feature on 0.10 #1344

Open
4 of 7 tasks
benebrice opened this issue Dec 14, 2020 · 5 comments · May be fixed by #1345
Open
4 of 7 tasks

Missing key_type feature on 0.10 #1344

benebrice opened this issue Dec 14, 2020 · 5 comments · May be fixed by #1345

Comments

@benebrice
Copy link

benebrice commented Dec 14, 2020

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've asked my question on Gitter and have not received a satisfactory answer.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

On 0.10, key_type still exists from 0.9 but is not manage.

Indeed, ResourceIdentity only handles primary key. It might work if key_type is actually the primary key but it's not. Errors are raising.

For example, with id as a primary key and uuid as key_type.

This is a part of the job. I'm not 100% confident with all side effects that update might have. Maybe @lgebhardt can help with his knowledge.

Gitter on 11th of December 2020

@benebrice benebrice changed the title Missing key_type feature on 0.10.0 Missing key_type feature on 0.10 Dec 14, 2020
@benebrice benebrice linked a pull request Dec 14, 2020 that will close this issue
12 tasks
@lgebhardt
Copy link
Member

@benebrice sorry I missed this in gitter. Could you explain the issue a bit more? You should be able to set the key type globally through the config like:

JSONAPI.configure do |config|
  config.resource_key_type = :uuid
end

or per resource with the key_type method in the resource declaration. This is put together in https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/basic_resource.rb#L765

I'm using uuid key types set in the config in several projects with version 0.10 so I believe it's working.

From your gitter comment I'm wondering if you have renamed the primary_key field from id to uuid.

@benebrice
Copy link
Author

No worries for the delay!
Actually, I'm not changing resource_key_type so my primary key is still id but I'm displaying an uuid through the API. So I've changed key_type :uuid on my base resource.
If you do that, you'll see that there is an issue. I've tried to fix it. It's working for #index but I've broken a lot of things.

@lgebhardt
Copy link
Member

lgebhardt commented Jan 8, 2021

@benebrice I added a branch to the peeps_uuids app, https://github.com/cerebris/peeps-uuids/tree/base_resource_test, that shows I think what you are doing. The resources are derived from a base resource:

class BaseResource < JSONAPI::Resource
  root_resource
  caching
  key_type :uuid
end

and the config no longer sets the resource_key_type. It seems to be working.

@tommy-russoniello
Copy link
Collaborator

@benebrice are you still having this issue?

@benebrice
Copy link
Author

I did not have time to check It but take a look at @lgebhardt comment above. I didn't test it yet but if it's working, I made a mistake on my configuration. 🙂

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

Successfully merging a pull request may close this issue.

3 participants