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

Relationship keys are not getting converted to camelCase #106

Open
nataliepatton13 opened this issue Mar 28, 2022 · 1 comment
Open

Relationship keys are not getting converted to camelCase #106

nataliepatton13 opened this issue Mar 28, 2022 · 1 comment

Comments

@nataliepatton13
Copy link

When defining a model, it appears that only attributes are getting converted to camelCase but relationship keys have to be defined in snake case or else I get the error Unknown type "appointment_requests"

I have an Appointment model that is currently setup like this:

const Appointment = ApplicationRecord.extend({
  static: {
    jsonapiType: "appointments",
  },
  attrs: {
    appointmentRequests: hasMany(),
  },
});

It has a has many relationship to the AppointmentRequests model that looks like this:

const AppointmentRequests = ApplicationRecord.extend({
  static: {
    jsonapiType: "appointmentRequests",
  },
  attrs: {
    appointment: belongsTo(),
    startTime: attr(),
  },
});

However, I currently have to change appointmentRequests to appointment_requests in both models in order to be able to access the related appointment requests from an appointment record. It seems like I should be able to define the relationships in camelCase since other attributes get converted from snake_case to camelCase correctly. Has anyone else seen or run into this issue before?

@geeosh
Copy link

geeosh commented Jun 15, 2022

@nataliepatton13 I set jsonapiType to what comes from the server, which is in snake_case. Then you can use camelCase relationship names everywhere, such as appointmentRequests.

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

2 participants