在 Sails.js(吃水线)中的嵌套字段(关系内)上的搜索结果

Search results on nested fields (within relations) in Sails.js (waterline)

本文关键字:关系 字段 搜索结果 嵌套 Sails js      更新时间:2023-09-26

我正在使用Sails.js(waterline orm)来制作API

我需要但无法完成的是过滤表(模型)中的结果,搜索所有字段,包括嵌套字段:

即:


GET /users/?filter=admin

>>> [{ id: 1, email: 'homer@example.com', role: 'admin' }, { id: 3, email: 'lisa@example.com', role: 'admin' }]


GET /users/?filter=homer

>>> [{ id: 1, email: 'homer@example.com', role: 'admin' }]


型号/用户.js

{
    attributes: {
        email: {
            type: 'string'
        },
        role: {
            model: 'Roles'
        }
    }
}

模特/角色.js

{
    attributes: {
        role: {
            type: 'string'
        }
    }
}

您似乎正在使用包含的 REST API 作为水线。我在最近的一个项目中使用了sails,我可以说与JavaScript库相比,REST api缺少功能。

我建议您使用 sails 控制器创建自己的 api 端点,并直接用 JavaScript 编写请求(使用 where 和填充)。