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

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

Closed
nataliepatton13 opened this issue Mar 23, 2022 · 1 comment

Comments

@nataliepatton13
Copy link

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 🤔

@nataliepatton13
Copy link
Author

nataliepatton13 commented Mar 24, 2022

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

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

1 participant