title: How to use findAll with associations in Sequelize
body: <p>I'm having problems to use the findAll() method with associations from Sequelize.
  I have two models: Posts and Authors (an author has many posts and one post has one author), that I have created with Sequelize-cli and then through the migration command <code>npx sequelize db migrate:all</code> i have created them in mysql. To keep things organized, I have the associations between the models in another migration file (created with <code>npx sequelize init:migrations</code>, after all the models already existent), so my code looks like this: </p>
  
  <p><strong>AUTHOR MODEL</strong></p>
  
  <pre><code>'use strict';
  module.exports = (sequelize, DataTypes) =&gt; {
    const Author = sequelize.define('Author', {
      authorName: { 
        type: DataTypes.STRING,
        validate: {
          is: ["^[a-z]+$",'i'], 
        }
      },
      biography: {
        type: DataTypes.TEXT,
        validate: {
          notEmpty: true,
        }
      }
    }, {});
    Author.associate = function(models) {
      Author.hasMany(models.Post);
    };
    return Author;
  };
  </code></pre>
  
  <p><strong>POST MODEL</strong></p>
  
  <pre><code>'use strict';
  module.exports = (sequelize, DataTypes) =&gt; {
    const Post = sequelize.define('Post', {
      title: { 
        type: DataTypes.STRING,
        validate: {
          is: ["^[a-z]+$",'i'],
          notEmpty: true,
        },
      },
      content: { 
        type: DataTypes.TEXT,
        validate: {
          notEmpty: true,
        },
      },
      likes: {
        type: DataTypes.INTEGER,
        defaultValue: 0,
        validate: {
          isInt: true,  
        },
      },
    }, {});
    Post.associate = function(models) {
      // associations can be defined here
    };
    return Post;
  };
  </code></pre>
  
  <p><strong>ASSOCIATIONS FILE (MIGRATION)</strong> (showing only parts that matter)</p>
  
  <pre><code>up: (queryInterface, Sequelize) =&gt; {
      return queryInterface.sequelize.transaction(t =&gt; {
        return Promise.all([
          queryInterface.addColumn('Posts','AuthorId', {
              type: Sequelize.INTEGER,
              references: {
                model: 'Authors',
                key: 'id',
              },
              onUpdate: 'CASCADE',
              onDelete: 'SET NULL',
          }, { transaction: t }),
          queryInterface.addColumn('Posts', 'ImagesId', {
              type: Sequelize.INTEGER,
              references: {
                model: 'Images',
                key: 'id',
              },
              onUpdate: 'CASCADE',
              onDelete: 'SET NULL',
          }, { transaction: t }),
          queryInterface.addColumn('Posts', 'CategoryId', {
            type: Sequelize.INTEGER,
            references: {
              model: 'Categories',
              key: 'id',
            },
            onUpdate: 'CASCADE',
            onDelete: 'SET NULL',
          }, { transaction: t }),
        ]);
      });
  </code></pre>
  
  <p>This is working fine apparently, since in Mysql-Workbench it shows me the following: <a href="https://i.stack.imgur.com/5Q9ml.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Q9ml.png" alt="forget about the images and categories"></a></p>
  
  <p>But, when I try to use the <a href="https://sequelize.org/master/manual/querying.html#relations---associations" rel="nofollow noreferrer">findAll()</a> like this:</p>
  
  <pre><code>const { Post, Author } = require('../models/index');
  
  function(response) {
     Post.findAll({ 
        attributes: ['id', 'title', 'content', 'likes'],
        include: {
          model: Author,
        }
     })
     .then(result =&gt; response.json(result))
       .catch(error =&gt; response.send(`Error getting data. Error: ${error}`));
  </code></pre>
  
  <p>It gives me the following <a href="https://sequelize.org/master/class/lib/errors/eager-loading-error.js~EagerLoadingError.html" rel="nofollow noreferrer">error</a>: </p>
  
  <blockquote>
    <p>SequelizeEagerLoadingError: Author is not associated to Post!</p>
  </blockquote>
  
  <p>So, I dont know anymore how to proceed. I've been trying many others approaches, but all of then unsuccessfully. I read already many other questions here in StackOverFlow about how to solve this sort of problem, but those were unsuccessfully too.</p>
  
  <p>Thanks in advance.</p>