【问题标题】:Sails-mongo many to many association not workingSails-mongo 多对多关联不起作用
【发布时间】:2015-04-29 01:48:19
【问题描述】:

我正在使用sails 0.10.5,并且我有两个模型如下,用于多对多关系。但我在提升应用程序时遇到错误。

模型 1) Category.js

attributes: {
        name: {
            type: 'string',
            required: true
        },
        features: {
            type: 'array'
        },
        desc: {
            type: 'string'
        },
        sub_cats: {
            collection: 'SubCategory',
            via: 'cats',
            dominant: true
        }
    }

模型 2) SubCategory.js

attributes: {

        cats: {
            collection: 'Category',
            via: 'sub_cats'
        },
        name: {
            type: 'string',
            required: true
        },
        features: {
            type: 'array'
        },
        desc: {
            type: 'string'
        }
    }

现在在提升帆应用程序时,总是会触发此错误

"C:\Program Files (x86)\JetBrains\PhpStorm 8.0.2\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" app.js

c:\wamp\www\holymantra\hm\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\utils.js:47
  return hop.call(obj, prop);
             ^
TypeError: Cannot convert null to object
    at hasOwnProperty (native)
    at exports.object.hasOwnProperty (c:\wamp\www\holymantra\hm\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\utils.js:47:14)
    at JoinTables.parseAttribute (c:\wamp\www\holymantra\hm\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\joinTables.js:148:26)
    at c:\wamp\www\holymantra\hm\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\joinTables.js:83:22
    at Array.forEach (native)

所以我很困惑(我的代码错误或sails-mongo 多对多关系有问题)

--ND

【问题讨论】:

    标签: node.js sails.js waterline sails-mongo


    【解决方案1】:

    这只是SubCategory.js 中的一个错字:应该是attributes 而不是attribute

    【讨论】:

    • 您可以尝试从控制台使用sails liftnode app.js 启动应用程序吗?
    • @NishchitDhanani 你还有其他模特吗?
    • 是的,我已经尝试了所有的可能性。我还有其他模型,但这些模型在这一点上是相关的。
    【解决方案2】:

    希望您现在已经解决了您的问题!对于像我这样遇到此错误的其他人,balderdashy/waterline-schema 刚刚在https://github.com/balderdashy/waterline-schema/issues/17 发布了一条更有用的错误消息,它应该可以帮助您找出您的特定问题。因为截至今天 (2015-04-28) npm install 没有为您提供这个最新版本,您可以通过执行以下操作手动修复它:

    1. 导航到node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema(注意:这可能在您的全局sails 目录中)
    2. joinTables.js 替换为https://github.com/balderdashy/waterline-schema/blob/8f5a44d076ca36edea409bf41ac2cdbf760c2c59/lib/waterline-schema/joinTables.js

    我知道这并不能完全回答您关于哪里出了问题的问题,但希望它会给其他有该错误的人提供更快解决问题的工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 1970-01-01
      相关资源
      最近更新 更多