Hi,
I’m running into a similar situation as in this thread and wanted to get some feedback on my approach. Here’s the gist:
An Appointment
may have 1 or more Pets
and 1 or more Services
. However, each Service
may or may not apply to a Pet
. Here’s a real-world example of how this related: a customer chooses an appointment date, they choose the pets that are a part of the appointment and they choose all of the services. For example, appointment is on 4/23 at 2:30, Max and Lady are the pets involved, and the 30 minute walk and Medication services are selected. Both pets need to be walked, but only Lady needs medication. This last sentence is the the relation I’m trying to represent.
Representing the Pets
and Services
relationship with Appointment
is trivial; the part that is throwing me off is how to indicate that a Pet
is associated with 0 or more services. Here’s what I was thinking:
{
"data": [{
"type": "appointment",
"id": "1",
"attributes": {
...
},
"relationships": {
"services": {
"data": [{
"type": "service",
"id": "1"
}, {
"type": "service",
"id": "2"
}]
},
"pets": {
"data": [{
"type": "pet",
"id": "1",
"meta": {
"services": [1]
}
}, {
"type": "pet",
"id": "2",
"meta": {
"services": [1, 2]
}
}]
}
}
}]
}
Is there a better way to represent this?
Thanks!
James