具有多对多关联的SequelizeEagerLoadingError

时间:2018-11-27 12:41:03

标签: sequelize.js

我有一个联接表ManufacturerTab。我正在尝试获取属于特定制造商的制造商标签列表。但是,我遇到了一个错误SequelizeEagerLoadingError

型号:

'use strict';
module.exports = (sequelize, DataTypes) => {
  var ManufacturerTab = sequelize.define('ManufacturerTab', {

  });
  var Manufacturer = sequelize.define('Manufacturer', {});
  var TabsTemplate = sequelize.define('TabsTemplate', {});

  ManufacturerTab.associate = function (models) {};
  Manufacturer.belongsToMany(TabsTemplate, { through: ManufacturerTab });
  TabsTemplate.belongsToMany(Manufacturer, { through: ManufacturerTab });

  return ManufacturerTab;
};

路线

app.use('/manufacturers/:manufacturer_id/manufacturer-tabs', manufacturer_tabs);

/* Get Manufacturer Tabs List */
router.get('/', function(req, res) {
  var manufacturer_id = req.params.manufacturer_id;
  models.Manufacturer.findAll({
    where: {
      id: manufacturer_id
    },
    include: [{
        model: models.TabsTemplate
    }]
  }).  
  then(function(manufacturer_tabs) {  
      res.status(200).json(manufacturer_tabs);  
  }, function(error) {  
      res.status(500).send(error);  
  });  
});

0 个答案:

没有答案