graphiti-api / graphiti

Stylish Graph APIs

Home Page:https://www.graphiti.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resources are not being included when the relationship name has an underscore in it

nataliepatton13 opened this issue · comments

When making a request to the endpoint /appointments?include=appointment_requests, the related appointment requests are not being included in the response.

Here is my code for the appointment resource:

class AppointmentResource < ApplicationResource
  primary_endpoint '/appointments'
  self.model = Appointment
  has_many :appointment_requests, resource: CustomerPortal::AppointmentRequestResource
end

and here is the appointment request resource:

class AppointmentRequestResource < ApplicationResource
  primary_endpoint '/appointment_requests'
  self.model = AppointmentRequest

  filter :appointment_id, :integer
  belongs_to :appointment, resource: CustomerPortal::AppointmentResource
 end

The response body looks like this:

{
	"data": {
		"id": "1",
		"type": "appointments",
		"relationships": {
			"appointmentRequests": {
				"links": {
					"related": "localhost/api/v1/appointment_requests?filter[appointment_id]=1"
				}
			}
		}
	},
	"meta": {}
}

If however, I add an alias name for the appointment_requests relationship on the appointment model like this:

alias_attribute :requests, :appointment_requests

and then I update the has_many association on the appointment resource to be requests instead of appointment_requests, the appointment requests are included in the response as expected.

So it seems to be working fine as long as there isn't an underscore in the relationship name 🤔

Closing this issue because I realized it's the same problem from this issue.