I have to create a Rest API to a directional graph model using strongloop loopback. I have a collection of nodes and a collection of relationships relating the nodes. The relationship collection stores the nm relations.
In the models/node.json I have included the following relations
"relations": {
"incomingNodes": {
"type": "hasMany",
"model": "node",
"through": "relationship",
"foreignKey": "endNode"
},
"outgoingNodes": {
"type": "hasMany",
"model": "node",
"through": "relationship",
"foreignKey": "startNode"
}
}
In the models/relationships.json:
"relations": {
"startNode": {
"type": "belongsTo",
"model": "node",
"foreignKey": "nodeId"
},
"endNode": {
"type": "belongsTo",
"model": "node",
"foreignKey": "nodeId"
}
}
The explorer is populated as expected, but if I create a relation using the Rest API
/nodes/{id}/incomingNodes/rel/{fk}
and look into the database, things are getting weird. The following data is written:
{
"id": "55ff1072b88c93a82ae527ea", <--id of the new relationship
"nodeId": "55fef9a156468fe629d94ac8" <-- id of the {fk}
}
I would expect that something like this:
{
"id": "55ff1072b88c93a82ae527ea", <--id of the new relationship
"startNode": "55fef9a156468fe629d94ac8", <-- id of the {fk}
"endNode": "55fef9a156468fe629d94ac8" <-- id of the {id}
}
I've tried all kinds of combinations, but just can't get it working.
Please help