title: Cannot read property 'define' of undefined ( sequelize defining model)?
body: <p>I'm using node.js version 10.13.0, with SEQUELIZE version 4.42.0, and I try to define a set of models, but i have a problem in the date.js file, it says :</p>
  
  <blockquote>
    <p>Cannot read property 'define' of undefined
    it happens when i run a test with connect.js file.
    this is the structure of the project :</p>
  </blockquote>
  
  <p><img src="https://ibb.co/fSBhLjy" alt="project structure image 1">
  <img src="https://ibb.co/2ZRy2KW" alt="project structure image 2"></p>
  
  <p>so i do the following in date.js</p>
  
  <pre><code>function init(){
  console.log(sequelize);
  const Date = sequelize.define('date' , {
      id : {
          type : sequelize.DataTypes.BIGINT(5),
          allowNull : false,
          autoIncrement : true,
          primaryKey : true
      },
      starting_date : {
          type : sequelize.DataTypes.DATE,
          allowNull : true,
          defaultValue : null
      },
      ending_date : {
          type : sequelize.DataTypes.DATE,
          allowNull : true,
          defaultValue: null
      },
      now : {
          type : sequelize.DataTypes.BOOLEAN,
          allowNull : true,
          defaultValue : true
      }
  });
  
  Date.associate = function(models){
      Date.belongsToMany(models.email , {through : models.task});
      Date.belongsToMany(models.user , {through : models.task});
  };
  
  return Date;
  }
  module.exports = init();
  </code></pre>
  
  <p>and this the connect.js script :</p>
  
  <pre><code>const fs = require('fs');
  const path = require('path');
  const Sequelize = require('sequelize');
  const basename = path.basename(__filename);
  const env = 'development';
  const config = require('../config/config')[env];
  
  const sequelize  = new Sequelize(config.database.database_name, 
  config.database.username, config.database.password, 
  config.database.database_config);
  
  var db = {
      sequelize : sequelize,
      Sequelize : Sequelize
  };
  
  fs.readdirSync("./models/").filter(file =&gt; {
      return (file.indexOf('.') !== 0) &amp;&amp; (file !== basename) &amp;&amp; 
  (file.slice(-3) === '.js');
  }).forEach(file =&gt; {
      var model = sequelize.import(path.join("./models", file));
      db[model.name] = model;
  });
  
  Object.keys(db).forEach(modelName =&gt; {
      if (db[modelName].associate) {
         db[modelName].associate(db);
      }
   });
  
   db.authenticate().then(() =&gt; {
  console.log('database worked !!!');
  }).catch(error =&gt; {
     console.log(error.stack);
  });
  
  
  module.exports = db;
  </code></pre>
  
  <p>the whole project is in this link: <a href="https://github.com/ekkatharisi/mailer" rel="nofollow noreferrer">https://github.com/ekkatharisi/mailer</a></p>
  
  <p>as final result, I want to build this database as described in scheme :
  <img src="https://ibb.co/z41QNY1" alt="class diagram scheme"></p>
  
  <p>thank you in advance.</p>