【问题标题】:Sails.js add attribute from another table to a modelSails.js 将属性从另一个表添加到模型
【发布时间】:2014-11-01 16:03:57
【问题描述】:

我正在尝试从不同的表中为模型提取额外的属性。 我一直在尝试关联,但创建一个额外的模型并将其与我的原始模型关联似乎是错误的。

这是我的模型 Company.js

module.exports = {
    schema: true,
    autoCreatedAt: false,
    autoUpdatedAt: false,
    autoPK: false, 

    attributes: {
        name: {
            type: 'string'
        },
        url: {
            type: 'string'
        },
        summary: {
            type: 'text'
        }
    }
};

我在 MySQL 中有另一个表,其中包含两个列 crunchbase_url 和 company_id,我想将 crunchbase_url 拉入 Company 模型,在不迁移数据库的情况下最好的方法是什么(不幸的是,这不是一个选项)。

谢谢,

【问题讨论】:

    标签: sails.js


    【解决方案1】:

    好吧,事实证明文档很好,通过简单地创建另一个模型并使用与 via 连接的一对多关联,所有工作都像一个魅力。

    但是,有一个错误让我失望:

    When defaultLimit is set to -1, the find action return an empty list if there are associations.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-12
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多