graphiti-api / spraypaint.js

Graphiti Client / Javascript ORM / JSONAPI
MIT License
107 stars 69 forks source link

Relationship keys are not getting converted to camelCase #106

Open nataliepatton13 opened 2 years ago

nataliepatton13 commented 2 years ago

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 commented 2 years ago

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