0

我有两个模型都与用户表有关系,即项目用户对用户有一个外键,评论也属于用户

对于项目用户模型(projectusers.js文件):

var User = require('./users').table;
var pusers_table = db.define('project_users', { ... });
pusers_table.belongsTo(User);
User.hasMany(pusers_table);

评论模型(comments.js文件):

var User = require('./users').table;
var comments_table = db.define('comments', { ... });
comments_table.belongsTo(User);
User.hasMany(comments_table);

请注意,所有三个(用户、项目用户和评论)都在不同的 JS 文件中定义,并使用 requirejs 包含在内。

  TypeError: Cannot read property 'associationType' of null
        at null.<anonymous> (./node_modules/sequelize/lib/dialects/abstract/query.js:328:54)
        at Array.forEach (native)
        at module.exports.buildAssociatedDaoInstances (./node_modules/sequelize/lib/dialects/abstract/query.js:324:21)
        at module.exports.transformRowWithEagerLoadingIntoDao (./node_modules/sequelize/lib/dialects/abstract/query.js:295:37)
        at null.<anonymous> (./node_modules/sequelize/lib/dialects/abstract/query.js:282:50)
        at Array.map (native)
        at module.exports.transformRowsWithEagerLoadingIntoDaos (./node_modules/sequelize/lib/dialects/abstract/query.js:281:58)
        at module.exports.handleSelectQuery (./node_modules/sequelize/lib/dialects/abstract/query.js:262:54)
        at module.exports.AbstractQuery.formatResults (./node_modules/sequelize/lib/dialects/abstract/query.js:68:34)
        at null.<anonymous> (./node_modules/sequelize/lib/dialects/mysql/query.js:32:35)
        at Query.Sequence.end (./node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
        at Query._handleFinalResultPacket (./node_modules/mysql/lib/protocol/sequences/Query.js:143:8)
        at Query.EofPacket (./node_modules/mysql/lib/protocol/sequences/Query.js:127:8)
        at Protocol._parsePacket (./node_modules/mysql/lib/protocol/Protocol.js:172:24)
        at Parser.write (./node_modules/mysql/lib/protocol/Parser.js:62:12)
        at Protocol.write (./node_modules/mysql/lib/protocol/Protocol.js:37:16)
        at Socket.ondata (stream.js:51:26)
        at Socket.EventEmitter.emit (events.js:117:20)
        at Socket.<anonymous> (_stream_readable.js:710:14)
        at Socket.EventEmitter.emit (events.js:92:17)
        at emitReadable_ (_stream_readable.js:382:10)
        at emitReadable (_stream_readable.js:378:5)
        at readableAddChunk (_stream_readable.js:143:7)
        at Socket.Readable.push (_stream_readable.js:113:10)
        at TCP.onread (net.js:511:21)

我刚刚尝试升级 sequelize,现在在 sequelize@1.7.0-alpha1 上,但我仍然遇到问题。

请注意,如果我只定义了其中一个,我不会收到错误消息(即,如果我删除评论中的关系,项目用户可以正常工作,反之亦然)。

我究竟做错了什么?

4

0 回答 0