【问题标题】:Conditional sails model schemas条件帆模型模式
【发布时间】:2014-10-09 06:55:19
【问题描述】:

我正在尝试根据是否存在其他模型来编写条件模型架构。

例如,如果存在模型“消息”,则添加收件箱/发件箱:

var userSchema = {
    attributes: {
    ...
    }
}

var messageSchema = {
    attributes: {
        inbox: {
            collection: 'Message'
             },
        outbox: {
            collection: 'Message'
             }
    }
};


if (<function to check that Message Model is available)
    _.merge userSchema, messageSchema

有可能做这样的事情吗?

【问题讨论】:

    标签: orm sails.js waterline


    【解决方案1】:

    我认为我们需要一个插件上的“预模型加载”fase 和一个钩子来允许其他模块确实改变它的结构,如 drupal 7 方案。

    您冷导出一个函数以在插件 npm 加载器中插入此“fase 功能”,就像我对默认配置所做的那样:https://github.com/wejs/we-plugin/blob/master/lib/index.js#L18 并在 https://github.com/wejs/we-example/blob/master/app.js#L63 中设置

    【讨论】:

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