spraypaint.js icon indicating copy to clipboard operation
spraypaint.js copied to clipboard

Relationship keys are not getting converted to camelCase

Open nataliepatton13 opened this issue 2 years ago • 1 comments

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?

nataliepatton13 avatar Mar 28 '22 14:03 nataliepatton13

@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.

geeosh avatar Jun 15 '22 21:06 geeosh