【问题标题】:Search results on nested fields (within relations) in Sails.js (waterline)Sails.js(水线)中嵌套字段(关系内)的搜索结果
【发布时间】:2016-03-07 16:01:52
【问题描述】:

我正在使用 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' }]


模型/Users.js

{
    attributes: {
        email: {
            type: 'string'
        },

        role: {
            model: 'Roles'
        }
    }
}

模型/Roles.js

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

【问题讨论】:

    标签: javascript node.js sails.js waterline


    【解决方案1】:

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

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

    【讨论】:

    • 这不回答我的问题,很懒。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2022-06-15
    相关资源
    最近更新 更多