【问题标题】:How do I perform a nested join in sails.js and waterline?如何在sails.js 和水线中执行嵌套连接?
【发布时间】:2014-10-17 16:31:29
【问题描述】:

在sails.js我有以下型号:

网站

module.exports = {
  attributes: {
    name: {
        type: 'string',
        required: true
    },
    active: {
        type: 'boolean',
        defaultTo: false
    },
    pages: {
        collection: 'page',
        via 'site'
    }
  }
};

页面

module.exports = {
  attributes: {
    name: {
        type: 'string',
        required: true
    },
    site: {
        model: 'site',
        required: true
    },
    modules: {
        collection: 'module',
        via 'page'
    }
  }
};

模块

module.exports = {
  attributes: {
    module: {
        type: 'string',
        required: true
    },
    page: {
        model: 'page',
        required: true
    }
  }
};

当我调用 GET /Site/1 时,我得到以下信息:

{
    "pages": [
        {
            "name": "First page",
            "site": 1,
            "createdAt": "2014-08-23T17:57:41.562Z",
            "updatedAt": "2014-08-23T17:57:41.562Z",
            "id": 1
        }
    ],
    "name": "First site",
    "createdAt": "2014-08-23T17:56:57.143Z",
    "updatedAt": "2014-08-23T17:56:57.143Z",
    "id": 1
}

我正在使用 MongoDB,这很容易建模为嵌套文档。不幸的是,我认为 Waterline 不支持这一点,因此有关联/连接。

我可以看到它成功地输出了与站点关联的每个页面,我该如何使其同时输出与每个页面关联的模块列表?

【问题讨论】:

标签: node.js sails.js waterline


【解决方案1】:

This thread 可能会有所帮助。本质上,目前还没有直接的方法来获取嵌套关联。

【讨论】:

    猜你喜欢
    • 2015-01-03
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    相关资源
    最近更新 更多