loopbackjs - Get full json struct in a belongsTo relation -


i'm trying setup basic model relation in loopback creating belongsto relationship.

i have 2 models defined this:

contract.json

{   "name": "contract",   "base": "persistedmodel",   "idinjection": false,   "options": {     "validateupsert": true   },   "mssql": {     "schema": "dbo",     "table": "contract"   },   "properties": {     "contractid": {        // property stuff     },   "validations": [],   "relations": {     "employee": {       "type": "belongsto",       "model": "employee",       "foreignkey": ""     }   },   "acls": [],   "methods": [] } 

employee.json

{   "name": "employee",   "base": "persistedmodel",   "idinjection": false,   "options": {     "validateupsert": true   },   "mssql": {     "schema": "dbo",     "table": "employee"   },   "properties": {     "employeeid": {        // property definitions...     }   },   "validations": [],   "relations": {     "contracts": {       "type": "hasmany",       "model": "contract",       "foreignkey": ""     }   },   "acls": [],   "methods": [] } 

when get request on contract specfic id result:

calling: /api/contracts/55

{   "contractid": 55,   "employeeid": 83 } 

which fine far. when get request on contract, getting employees expect ouput this:

calling: /api/contracts/55/employee

{   "contractid": 55,   "employee": {       "employeeid": 83   } } 

but instead i'm getting employee object without contract:

{     "employeeid": 83 } 

why that?

am doing wrong? or have wrong expectations?

you can /api/contracts/55?filter[include]=employee

or:

/api/contracts/55?filter={"include":"employee"} 

you can set contract model default scope include employee objects adding "scope" section:

"scope": {     "include": "employee"   } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -