The _expand query param would work with a belongsTo relationship but not with hasMany relationship.
For this db.json:
{
"posts": [{
"id": 1,
"title": "My post title",
"userId": 2,
"tags": [1, 2]
}],
"users": [...],
"tags": [...]
}
This posts/3?_expand=user work since the post has a userId foreign key as "userId" : 2, it's just a belongsTo relationship, but posts/3?_expand=tags will not work since it will look for tagsId property inside the post, and deal with the value as a number not number[], so expect "tagsId": n not "tagsId": [x, y, z].
Updating the expand function fixes this issue, now it will check first if the key exists in the resource, so check first for "tags" before tagsId, means before adding the Id suffix:
The
_expand
query param would work with abelongsTo
relationship but not withhasMany
relationship.For this db.json:
This
posts/3?_expand=user
work since the post has auserId
foreign key as"userId" : 2
, it's just abelongsTo
relationship, butposts/3?_expand=tags
will not work since it will look fortagsId
property inside thepost
, and deal with the value as a number not number[], so expect"tagsId": n
not"tagsId": [x, y, z]
.Updating the
expand
function fixes this issue, now it will check first if the key exists in the resource, so check first for"tags"
beforetagsId
, means before adding theId
suffix:Then check if its value is an array, e.g.
"tags": [1, 2]