Can js-data create relations on nested objects? Here is an example:
GET /card/2
{
"id": 2,
"name": "foo",
"action": { // <-- nested object
"typeId": 1, // foreign key to actionType.id
"param0": 20
}
}
GET /action-types
[{
"id": 1,
"name": "Jump",
"paramsMeta": [{
"name": "Distance",
"max": 30
}]
}, {
"id": 2,
"name": "Damage",
"paramsMeta": [{
"name": "amount",
"min": 0
}, {
"name": "isRelative",
"type": "Boolean"
}]
}]
resources.js:
DS.defineResource({
name: 'card',
relations: {
hasOne: {
actionType: {
localField: 'action.type',
localKey: 'action.typeId'
}
}
}
});
DS.defineResource(
name: 'actionType',
endpoint: 'action-types'
);
What I need is to initialize property card.action.type
. But in current example property card['action.type']
is initialized and that's not what I want. To be more specific, current card
Object after js-data processing is:
> console.log(DS.get('card', 2));
>
{
id: 2,
name: 'foo',
'action.type': { id: 1, name: 'Jump', ... } // <-- reference to actionType
action: {
typeId: 1, param0: 20
}
}
But I need the structure to be like this:
> console.log(DS.get('card', 2));
>
{
id: 2,
name: 'foo',
action: {
typeId: 1,
type: { id: 1, name: 'Jump', ... }, // <-- reference to actionType
param0: 20
}
}
js-data version: 2.9.0