我正在使用分子微服务和postgres数据库与模块moleculer-db-adapter-sequelize和Sequelize。每个服务都有一个表模型。例如,user.service.js有用户表模型,application.service.js有应用表模型。我希望使用join从两个表中获取数据。我试过使用联接查询,但它返回。
关系不存在
如何在分子结构中连接两个模型?
发布于 2021-06-21 09:34:42
moleculer-db的工作是一个服务一表的概念.您应该编写自定义DB服务来实现多个模型&联接。在Moleculer级别,可以使用populate连接服务之间的数据。
填充示例:
settings: {
fields: ["_id", "author", "article", "body", "createdAt", "updatedAt"],
populates: {
"author": {
action: "users.get",
params: {
fields: ["_id", "username", "bio", "image"]
}
}
}
},https://stackoverflow.com/questions/68047258
复制相似问题