当我尝试使用多对多关联将一个集合与另一个集合关联时,我收到以下错误:
使用sails-mongo:
TypeError: Cannot read property 'where' of undefined
at _afterFetchingJunctorRecords (/Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/waterline-cursor/cursor/populateBuffers.js:131:35)
at /Users/grant/Sites/sails/test/node_modules/sails-mongo/lib/collection.js:103:5
at /Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/cursor.js:172:16
at commandHandler (/Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/cursor.js:720:16)
at /Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/db.js:1874:9
at Server.Base._callHandler (/Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
at /Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
at MongoReply.parseBody (/Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/Users/grant/Sites/sails/test/node_modules/sails-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
at emit (events.js:95:17)
使用sails-postgresql:
TypeError: Cannot convert null to object
at hasOwnProperty (native)
at utils.object.hasOwnProperty (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-sequel/sequel/lib/utils.js:28:14)
at /Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-sequel/sequel/where.js:261:11
at Array.forEach (native)
at WhereBuilder.complex (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-sequel/sequel/where.js:178:36)
at complexWhere (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-sequel/sequel/index.js:245:16)
at find (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-sequel/sequel/index.js:85:23)
at Cursor.populateBuffers [as $populateBuffers] (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/lib/adapter.js:547:31)
at Cursor.run (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-cursor/cursor/cursor.js:45:8)
at runJoins (/Users/grant/Sites/sails/test/node_modules/sails-postgresql/node_modules/waterline-cursor/index.js:51:10)
测试项目
我创建了一个示例 Sails 应用程序来演示该问题并允许其他人测试/调试:https ://github.com/gnestor/sails-assoications-issue
重现:
尝试使用关联创建新记录(我尝试使用 Sails 控制台、Blueprints API 和控制器内部):
Event.create({source: 'http://domain.com/event/1', posted_by: {source: 'http://domain.com/feed/1'}}).exec(console.log)
Event.create({source: 'http://domain.com/event/3', venue: {source: 'http://domain.com/feed/2'}}).exec(console.log)
Event.create({source: 'http://domain.com/event/2', reposted_by: [{source: 'http://domain.com/feed/2'}, {source: 'http://domain.com/feed/4'}]}).exec(console.log)
结果
您会注意到前两个有效(一对多关联),但第三个无效(多对多关联)。我已经通过多种方式对此进行了测试(使用 Sails 控制台、Blueprints API 和内部控制器)。
值得注意的是,它确实适用于sails-disk,但不适用于sails-mongo、sails-postgresql 或sails-mysql,所以我可能做错了什么......
Sails-mongo 上的问题链接:https ://github.com/balderdashy/sails-mongo/issues/227sails-postgresql 上的问题链接: https : //github.com/balderdashy/sails-postgresql/issues/130