TypeError:无法读取未定义风帆的属性“集合”

我正在使用sails-sqlserver作为我的适配器,只是试图在其中一个follwing模型的数据库中创build一个新的行。

这是第一个模型:

// Roles.js module.exports = { autoCreatedAt: false, autoUpdatedAt: false, attributes: { name: { type: 'string' }, approval_level: { model: 'approval_levels' }, specified: { type: 'boolean' }, entity_operations: { collection: 'entity_operations', via: 'roles', dominant: true }, users: { collection: 'system_users', via: 'role' } }, createRole: function (name, approval_level, cb) { values = { name: name, approval_level: approval_level }; Roles.create(values).exec(cb); }, getAll: function (cb) { Roles.find().exec(cb); } }; 

这是第二个模型:

 // Entity_Operations.js module.exports = { autoCreatedAt: false, autoUpdatedAt: false, attributes: { entity_name: { type: 'string' }, operation: { model: 'operations' }, roles: { collection: 'roles', via: 'entity_operations' } }, getAll: function (cb) { Entity_operations.find().exec(cb); } }; 

这两种模式有着多种多样的关系,我们试图做的就是:

 Entity_operations.create({ entity_name: 'example', operation: 6 }).exec((err, entity: Entity_operations) => { console.log(entity); }); 

那么这个错误出来没有解释任何可以帮助我知道这个错误是从哪里来的:

  /opt/nodejs/back-heaven/dev/node_modules/sails-sqlserver/lib/adapter.js:435 Object.keys(connections[connection].collections[collection].definition).forEach(function(key) { ^ TypeError: Cannot read property 'collections' of undefined at Object.getPrimaryKey (/opt/nodejs/back-heaven/dev/node_modules/sails-sqlserver/lib/adapter.js:435:42) at Object.create (/opt/nodejs/back-heaven/dev/node_modules/sails-sqlserver/lib/adapter.js:374:24) at module.exports.create (/opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/adapter/dql.js:84:13) at child.createValues (/opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/query/dql/create.js:220:16) at /opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/query/dql/create.js:74:20 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:726:13 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:52:16 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:269:32 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:44:16 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:723:17 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:167:37 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:52:16 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:269:32 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:44:16 at child.<anonymous> (/opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/utils/schema.js:152:44) at fn (/opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/utils/callbacksRunner.js:41:10) at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:181:20 at iterate (/opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:262:13) at Object.async.forEachOfSeries.async.eachOfSeries (/opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:281:9) at Object.async.forEachSeries.async.eachSeries (/opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:214:22) at Object.runner.beforeCreate (/opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/utils/callbacksRunner.js:44:9) at /opt/nodejs/back-heaven/dev/node_modules/waterline/lib/waterline/query/dql/create.js:180:17 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:718:13 at iterate (/opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:262:13) at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:274:29 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:44:16 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:723:17 at /opt/nodejs/back-heaven/dev/node_modules/async/lib/async.js:167:37 

当我试图在一个控制器相同的代码,它试图在我自己的实施播种机之前它启动我以编程方式使sails对象,并调用sails.load

喜欢这个 :

 let myApp = new Sails(); myApp.load({}, (err) => { if (err) throw err; // this execute the seeds in the database seeder class let seeder = require(`../../api/seeders/${scope.args[0]}`); seeder.handle(() => { myApp.lower((err) => { if (err) throw err; console.log(`Seeder ` + scope.args[0] + ` finished seeding`); }); }); }); 

我也试过sails.lift(),仍然是一样的错误。

我已经find了问题,我只是做一个callback函数,应该调用sails.lower()卸载或closures帆我把它放在错误的地方,甚至在模型创build代码开始之前调用它。只是忘记在数据库callback函数中调用它。

所以,对于在风帆中遇到同样问题的任何人,你的问题是风帆实际上没有加载,或者当你正在进行的操作开始启动的时候运行,但之后出于某种原因风帆停止了,这使得模型变得奇怪我希望sails能够在代码中处理这些错误,以显示出更具expression性的错误信息。

我希望这可以帮助任何人。