Hi all,I was trying to make hasMany relation of model with the same model itself like my model was ticket and in that relations defined are parentTickets and childTickets which are array of tickets and i made a mapping table 'ticketRelation' which is mapping table for the has many relationship.My models are following-
ticket model-
"relations":{
"parentTickets":{
"type":"hasMany",
"model":"ticket",
"foreignKey":"childId",
"through":"ticketRelation"
},
"childTickets":{
"type":"hasMany",
"model":"ticket",
"foreignKey":"parentId",
"through":"ticketRelation"
}
}
ticketRelation-
"relations":{
"pticket": {
"type": "belongsTo",
"model": "ticket",
"foreignKey": "parentId"
},
"ticket": {
"type": "belongsTo",
"model": "ticket",
"foreignKey": "childId"
}
}
My sample data is-
ticket id =1 has child tickets with id =2,3
so when i try to find parentTickets in ticket model by the following URL
http//localhost:3000/api/tickets?filter[include]=childTickets
it give me correct result ie ticket-id =1,childTickets=2,3
but whenever i try to find parentTickets for ticket by the following URL, it is not giving me correct result
http//localhost:3000/api/tickets?filter[include]=parentTickets
The data retrieved is-
ticket-id=1, parentTicket -1
so the problem i noticed is might be that loopback is expecting the relation name to be same as that of model name which we are specifying in the relation in the mapping table( ticketRelation) to retrieve the data.