无法读取属性' getTableName'未定义的

时间:2017-04-25 01:58:49

标签: javascript node.js sequelize.js

我试图在2个表之间建立连接,并使用两个表中的字段创建一个where子句,但我收到此错误:

Cannot read property 'getTableName' of undefined

这是我的模特:

module.exports = function(sequelize, DataTypes) {
  var AutomatedCampaign = sequelize.define("AutomatedCampaign", {
    id:  { 
          type: DataTypes.INTEGER, 
          autoIncrement: true, 
          primaryKey: true
        },
    campaign_name: DataTypes.STRING,
    campaign_label: DataTypes.STRING,
    medium: DataTypes.STRING,
    visible: DataTypes.INTEGER,


  }, {
    tableName: 'automated_campaigns',
    underscored: true,
    timestamps: true,
  }

  );

  return AutomatedCampaign;
};



module.exports = function(sequelize, DataTypes) {
  var AutomatedCampaignConfig = sequelize.define("AutomatedCampaignConfig", {
    id:  { 
          type: DataTypes.INTEGER, 
          autoIncrement: true, 
          primaryKey: true
        },

    environment_hash: DataTypes.STRING,
    campaign_id: DataTypes.STRING,
    event_trigger_1: DataTypes.STRING,
    time_trigger_after_event_1: DataTypes.STRING,
    event_constraint_1: DataTypes.STRING,
    event_value_1: DataTypes.STRING,
    event_timestamp_1: DataTypes.INTEGER,
    is_deleted: DataTypes.BOOLEAN,
    is_active: DataTypes.BOOLEAN,
    html_content: DataTypes.TEXT,
    has_product_feed: DataTypes.BOOLEAN,
    subject_line: DataTypes.STRING,


  }, {
    tableName: 'automated_campaign_configs',
    underscored: true,
    timestamps: true,
    classMethods: {
            associate : function(models) {
                AutomatedCampaignConfig.belongsTo(models.AutomatedCampaign, {foreignKey: 'campaign_id'})
            },
    },
  }

  );

  return AutomatedCampaignConfig;
};

这是我的疑问:

var AutomatedCampaign  = require('../models/index').AutomatedCampaign;
var AutomatedCampaignConfig = require('../models/index').AutomatedCampaignConfig;


    var values = { 

                    include: [{ 
                        model: AutomatedCampaign,
                        through: { where: { visible: 1, environment_hash: environment_hash } }
                    }]

                };

    AutomatedCampaignConfig
        .findAll(values)
        .then(function(automated_campaigns) {

            console.log('automated campaigns');
            console.log(automated_campaigns);


        });

0 个答案:

没有答案