vendredi 27 février 2015

Querying relations in loopback doesn't work via Angular SDK

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


Aucun commentaire:

Enregistrer un commentaire