0

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

4

2 回答 2

1

这只是一个错字SubCategory.js:它应该attributes代替attribute.

于 2015-02-06T12:50:15.670 回答
1

Hopefully you've solved your problem by now! For others like me who ran into this error, balderdashy/waterline-schema just released a more helpful error message at https://github.com/balderdashy/waterline-schema/issues/17 which should help you figure out your particular problem. Because as of today (2015-04-28) npm install does not get you this most recent version, you can manually fix it by doing the following:

  1. Navigate to node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema (note: this may be in your global sails directory)
  2. Replace joinTables.js with https://github.com/balderdashy/waterline-schema/blob/8f5a44d076ca36edea409bf41ac2cdbf760c2c59/lib/waterline-schema/joinTables.js

I know this doesn't exactly answer your question as to what went wrong, but hopefully it will give others with that error the tools to solve it more quickly.

于 2015-04-28T17:48:19.353 回答