Jaeyson Anthony Y.
Jaeyson Anthony Y.
AEAsh Elixir
Created by Jaeyson Anthony Y. on 5/14/2025 in #support
I want to load related records inside "relationships" key
Hi! I'm following the Ash book, specifically on loading related records:
json_api do
type "artist"
includes [:albums]
end
json_api do
type "artist"
includes [:albums]
end
Where I wanted to return the related records (:albums) of :artist resource and the attributes of :albums are already public. It returns:
{
"data": [
{
"attributes": {
"name": "Resonanz",
"inserted_at": "2025-05-14T10:04:02.255547Z",
"previous_names": [],
"updated_at": "2025-05-14T10:04:02.255547Z"
},
"id": "030a340b-2d9d-4961-ae5a-5c7b80a30215",
"links": {},
"meta": {},
"type": "artist",
"relationships": {
"albums": {
"data": [
{
"id": "272bb477-3416-42e1-bcb4-551f11d26ee8",
"type": "album"
<For some reason the attributes are public, but why I can't see it?>
}
],
"links": {},
"meta": {}
}
}
}
]
}
{
"data": [
{
"attributes": {
"name": "Resonanz",
"inserted_at": "2025-05-14T10:04:02.255547Z",
"previous_names": [],
"updated_at": "2025-05-14T10:04:02.255547Z"
},
"id": "030a340b-2d9d-4961-ae5a-5c7b80a30215",
"links": {},
"meta": {},
"type": "artist",
"relationships": {
"albums": {
"data": [
{
"id": "272bb477-3416-42e1-bcb4-551f11d26ee8",
"type": "album"
<For some reason the attributes are public, but why I can't see it?>
}
],
"links": {},
"meta": {}
}
}
}
]
}
I understand that the related records go in "included": ... key. But what I really wanted is to show the related attributes inside "relationships" key:
{
"data": [
{
"attributes": {
...
},
"id": "030a340b-2d9d-4961-ae5a-5c7b80a30215",
"type": "artist",
"relationships": {
"albums": {
"data": [
{
"id": "272bb477-3416-42e1-bcb4-551f11d26ee8",
"type": "album"
... <-- I want to see the attributes! :(
},
],
"links": {},
"meta": {}
}
}
}
]
}
{
"data": [
{
"attributes": {
...
},
"id": "030a340b-2d9d-4961-ae5a-5c7b80a30215",
"type": "artist",
"relationships": {
"albums": {
"data": [
{
"id": "272bb477-3416-42e1-bcb4-551f11d26ee8",
"type": "album"
... <-- I want to see the attributes! :(
},
],
"links": {},
"meta": {}
}
}
}
]
}
6 replies