I am trying to query a model relation I have two models 1. Workers 2. Skills
Worker hasMany Skills
I can query the api via the explorer http://localhost:3000/explorer/#!/Workers/prototype_get_skills and /api/Worker/:id/Skills url and it gives back a list of skills for a give Worker Id
The issue happens when i try to call the Worker.skills() method generated by Angular SDK where i get a 404 Not Found Error
Below is the Angular implementation that i have
angular.module('worker-dashboard').factory('WorkerDashboardSkillService',['Worker',
function(Worker){
function getWorkerSkills(worker){
return Worker.skills({
filter:
{
where:
{
"workerId" : worker
}
}
},function(data){
console.log(data);
},
function(err){
console.log(err);
})
}
function addWorkerSkills(worker,skill){
return Worker.skills.create(
{
"skillName": skill.name,
//TODO chabge below
"skillCategory": skill.name,
"workerId": worker
},function(data){
console.log(data);
},
function(err){
console.log(err);
})
}
return{
getWorkerSkills : getWorkerSkills,
addWorkerSkills : addWorkerSkills
}
}]);
I also tried an example loopback-getting-started-intermediate
Which has an example
$scope.reviews = Review.find({
filter: {
where: {
publisherId: $rootScope.currentUser.id
},
include: [
'coffeeShop',
'reviewer'
]
}
});
However this example is looks like for the belongsTo relation and when i tried modifying it couldn't do it
Edit : Adding Worker.json
{
"name": "Worker",
"base": "User",
"idInjection": true,
"properties": {
"workerName": {
"type": "string"
},
"workerFirstName": {
"type": "string"
},
"workerLastName": {
"type": "string"
},
"isWorkerBlackListed": {
"type": "boolean"
},
"workerBlacklistedByClient": {
"type": [
"string"
]
}
},
"validations": [],
"relations": {
"skills": {
"type": "hasMany",
"model": "Skills",
"foreignKey": "workerId"
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}
Skills.json
{
"name": "Skills",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"skillName": {
"type": "string"
},
"skillCategory": {
"type": "string"
}
},
"validations": [],
"relations": {
"worker": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": []
}