我使用與快遞sequelize,我定義我的模型是這樣sequelize belongsToMany給類型錯誤:未定義是不是一個函數
"use strict";
var Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
var Order = sequelize.define("Order",
{
status: {
type: Sequelize.INTEGER
},
notes: {
type: Sequelize.STRING
}
},
{
classMethods: {
associate: function(models) {
Order.belongsTo(models.User);
Order.belongsTo(models.Address);
Order.belongsToMany(models.Items);
}
}
}
);
return Order;
}
我正在試圖運行我的應用程序時,以下錯誤消息
Order.belongsToMany(models.Items);
^
TypeError: undefined is not a function
at sequelize.define.classMethods.associate (models/order.js:18:7)
at models/index.js:24:19
at Array.forEach (native)
at Object. (models/index.js:22:17)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
我index.js文件是一樣給出一個明確的是這裏例如:https://github.com/sequelize/express-example/blob/master/models/index.js
我的產品型號如下:
"use strict";
var Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
var Item = sequelize.define("Item", {
title: {
type: Sequelize.STRING
},
mrp: {
type: Sequelize.DECIMAL,
allowNull: false
},
sp: {
type: Sequelize.DECIMAL,
allowNull: false
},
desc: {
type: Sequelize.STRING
},
skuId: {
type: Sequelize.STRING,
allowNull: false
},
type: {
type: Sequelize.STRING
},
merchantId: {
type: Sequelize.STRING,
allowNull: false
},
categoryId: {
type: Sequelize.STRING,
allowNull: false
}
}
);
return Item;
}
我也試過在app.js中給belongsToMany但它不起作用。所有其他協會都正常工作。 請幫忙。
你使用的是什麼版本的sequelize?你怎麼打電話給'associate'? –
版本爲[email protected],關聯從index.js調用,與https://github.com/sequelize/express-example/blob/master/models/index.js – akshay202
相同嗯,訂單。 js對我來說看起來很好。你可以發佈你的代碼「Items」嗎? –