在环回中查询关系无法通过 Angular SDK 工作



我正在尝试查询模型关系我有两个模型1.工人2.技能

工人具备多种技能

我可以通过浏览器查询apihttp://localhost:3000/explorer/#/工人/原型_设置_技能和/api/Worker/:id/Skills url它会返回一个给定Worker Id 的技能列表

当我尝试调用Angular SDK生成的Worker.skills()方法时,会出现问题,在该方法中我得到了一个404未找到错误

下面是我有的Angular实现

 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
        }
    }]);

我还尝试了一个例子环回开始中间

有一个的例子

$scope.reviews = Review.find({
filter: {
where: {
publisherId: $rootScope.currentUser.id
},
include: [
'coffeeShop',
'reviewer'
]
}
});

然而,这个例子看起来像是belongsTo关系,当我尝试修改它时,它做不到

编辑:添加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": []
}

迟到总比不迟到好。我今天也遇到了同样的麻烦。您只需要添加角度相关性。

 angular 
 .module('app')
  //inject all the model you need
  .controller('ListBooksController', ['$scope', '$state', 'Book', 'Collection', 'Author', function($scope,
$state, Book, Collection, Author) {
  $scope.books = Book.find({
  filter: {
    include: [
     'author'
    //put the model you want to retrieve
    ]
  }
  });
  console.log($scope.books);
}])

最新更新