【问题标题】:Loopback include relations and where环回包括关系和位置
【发布时间】:2021-08-01 07:15:20
【问题描述】:

我有两个环回模型:userbackendUser。一个(用户)与环回一起存储,另一个(后端用户)存储在远程 mysql 数据库中。它们的关系基于user 的字段(backendUserId)对应于backendUserID 字段

有一种情况,我得到每个user 及其对应的backendUser。但我想根据一些 backendUser 值来获取用户。示例:我需要每个user,其中backendUser.role4

我使用这个过滤器来得到预期的结果:

{ include: { relation: "backendUser", scope: { where: { "role" : 4 } } } }

我的问题是我得到了每个 user 的数组,但只有当 role4 时,我才会得到相关的 backendUser。 where 仅适用于 backendUser 而不是整个实体。

我不知道是否清楚,但我确实需要这个。

【问题讨论】:

    标签: node.js relation loopback


    【解决方案1】:

    使用以下内容:

    {
        where: {
            role: 4,
            include: {
                relation: "backendUser",
                scope: {
                    where: { "role": 4 }
                }
            }
        }
    }
    

    【讨论】:

      【解决方案2】:
       {
              where: {
                // here specific object of query user
              },
              include: [
                {
                  relation: 'backendUser',
                  scope: {
                    where: {
                      role: 4,
                    },
                  },
                },
              ],
            }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-12
        • 1970-01-01
        相关资源
        最近更新 更多