快速休息和续集-复杂的嵌套查询。需要建议

时间:2018-10-20 16:36:51

标签: mysql node.js express jwt sequelize.js

我是序列化的新手,在一个项目中,我有三种模型:

g++ toy.cpp -fopenmp

我需要创建一个返回如下内容的查询:

获取/ api / projects /:id

Project({name: String}), 
Task({name: String}),
TaskCategory({name: String})

Project.hasMany(Task)
Task.belongsTo(TaskCategory) 

我真的很坚持。我知道我可以做这样的事情:

{
  "id": "1",
  "name": "Project 1",
  "tasks": [
    {
      "id": "1",
      "name": "task 1",
      "category": {
        "id": "1",
        "name": "category 1"
      }
    },
    {
      "id": "2",
      "name": "task 2",
      "category": {
        "id": "2",
        "name": "category 1"
      }
    }
  ],
  "taskCount": "2",
  "taskCountPerCategory": [
    {
      "id": "1",
      "category": {
        "id": "1",
        "name": "category 1"
      },
      "count": "2"
    },
    {
      "id": "2",
      "category": {
        "id": "2",
        "name": "category 2"
      },
      "count": "0"
    },
    {
      "id": "3",
      "category": {
        "id": "3",
        "name": "category 3"
      },
      "count": "0"
    },
    {
      "id": "4",
      "category": {
        "id": "4",
        "name": "category 4"
      },
      "count": "0"
    }
  ]
}

但是我对“ taskCount”,“ taskCountPerCategory”部分迷失了。

请注意,“ taskCountPerCategory”应检索系统中每个TaskCategory的任务计数。

0 个答案:

没有答案