【问题标题】:Moleculer sequlize get tables data by joinsMolecular sequelize 通过连接获取表数据
【发布时间】:2021-06-25 20:24:56
【问题描述】:

我正在使用带有模块 moleculer-db-adapter-sequelize 和 Sequelize 的分子微服务和 postgres 数据库。每个服务都有一个表模型。例如user.service.js 有用户表模型,application.service.js 有应用程序表模型。我想使用连接从两个表中获取数据。我尝试了连接查询,但它返回了

关系不存在

如何在分子结构中连接两个模型?

【问题讨论】:

    标签: node.js postgresql sequelize.js moleculer


    【解决方案1】:

    moleculer-db 是一个服务一个表的概念。您应该编写自定义数据库服务来实现多个模型和连接。 在分子级别,populate 可用于连接服务之间的数据。

    填充示例:

        settings: {
            fields: ["_id", "author", "article", "body", "createdAt", "updatedAt"],
            populates: {
                "author": {
                    action: "users.get",
                    params: {
                        fields: ["_id", "username", "bio", "image"]
                    }
                }
            }
        },
    

    【讨论】:

    • 你能提供一些在两个服务之间填充的示例代码
    • 我添加了一个例子。
    猜你喜欢
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    相关资源
    最近更新 更多