Currently given two tables Enquiries and People.
An association on Enquiries:
$this->belongsTo('Friends', ['className' => 'People', 'foreignKey' => 'friend_id']);
An association on People:
$this->hasMany('FriendEnquiries', ['className' => 'Enquiries', 'foreignKey' => 'friend_id']);
You would include this relationship in a query string like this:
http://localhost:8080/api/enquiries/1?include=friend
The response however currently would include the friend with the key people rather than friends. So the front-end then has no way of tying this data back to the friend association.
I believe this is incorrect and that it should include this data using the given query string key as the object key in the included node of the response.
So to be clear: this is the response from the above query with an inline comment showing the suggested change:
{
"data": {
"type": "enquiries",
"id": "1",
"attributes": {
"name": "RSVP"
},
"relationships": {
"friend": {
"links": {
"self": "\/api\/enquiries\/1\/relationships\/friend",
"related": "\/api\/enquiries\/1\/friend"
},
"data": {
"type": "people",
"id": "3"
}
}
},
"links": {
"self": "\/api\/enquiries\/f4882be5-53c8-4927-a2af-75e34488a103"
}
},
"included": [
{
"type": "people", //<---- this should be "friend"
"id": "3",
"attributes": {
"name": "George"
},
"relationships": {
"enquiries": {
"links": {
"self": "\/api\/people\/relationships"
}
}
},
"links": {
"self": "\/api\/people\/3"
}
},
}
}
Am I wrong?
Currently given two tables Enquiries and People.
An association on Enquiries:
An association on People:
You would include this relationship in a query string like this:
The response however currently would include the
friendwith the keypeoplerather thanfriends. So the front-end then has no way of tying this data back to thefriendassociation.I believe this is incorrect and that it should include this data using the given query string key as the object key in the
includednode of the response.So to be clear: this is the response from the above query with an inline comment showing the suggested change:
Am I wrong?