{"action":"closed","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/5103","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/5103/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/5103/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/5103/events","html_url":"https://github.com/sequelize/sequelize/issues/5103","id":123906263,"number":5103,"title":"Include not working even without declaring alias in model definition","user":{"login":"daniellizik","id":10506366,"avatar_url":"https://avatars.githubusercontent.com/u/10506366?v=3","gravatar_id":"","url":"https://api.github.com/users/daniellizik","html_url":"https://github.com/daniellizik","followers_url":"https://api.github.com/users/daniellizik/followers","following_url":"https://api.github.com/users/daniellizik/following{/other_user}","gists_url":"https://api.github.com/users/daniellizik/gists{/gist_id}","starred_url":"https://api.github.com/users/daniellizik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniellizik/subscriptions","organizations_url":"https://api.github.com/users/daniellizik/orgs","repos_url":"https://api.github.com/users/daniellizik/repos","events_url":"https://api.github.com/users/daniellizik/events{/privacy}","received_events_url":"https://api.github.com/users/daniellizik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-26T03:25:51Z","updated_at":"2015-12-29T11:50:54Z","closed_at":"2015-12-29T11:50:54Z","body":"Seems like the most common mistake with `include` is not specifiying `as` in the query, as it must be if it was declared in the model. I am not specifying any aliases but still receiving `Error: Person is not associated to VideoPeople`. I'm on 3.15.0 using sqlite3 3.1.1\r\n\r\n**`Person` model**\r\n\r\n    module.exports = (sequelize, Datatypes) {\r\n        var attrs = {\r\n            firstname: Datatypes.STRING\r\n        };\r\n        var options = {\r\n            classMethods: {\r\n                associate: function(models) {\r\n                    models.Person.belongsToMany(models.Video, { through: models.VideoPeople });\r\n                }\r\n            }\r\n        };\r\n        return sequelize.define(\"Person\", attrs, options);\r\n    };\r\n\r\n**`Video` model**\r\n\r\n    module.exports = (sequelize, Datatypes) {\r\n        var attrs = {\r\n            filename: Datatypes.STRING\r\n        };\r\n        var options = {\r\n            instanceMethods: {\r\n\r\n    /*         where the eager loading occurs            */\r\n\r\n                includeMany: function() {\r\n                    return sequelize.model(\"VideoPeople\").findAll({\r\n                        where: { videoId: this.dataValues.id },\r\n                        include: [\r\n                            { model: sequelize.model(\"Person\") }\r\n                        ]\r\n                    }).then(function(people) {\r\n                        return { people: people };\r\n                    });\r\n                } \r\n\r\n            },\r\n            classMethods: {\r\n                associate: function(models) {\r\n                    models.Video.belongsToMany(models.Person, { through: models.VideoPeople });\r\n                }\r\n            }\r\n        };\r\n        return sequelize.define(\"Video\", attrs, options);\r\n    };\r\n\r\n**`VideoPeople` model**\r\n\r\n    module.exports = (sequelize, Datatypes) {\r\n        var attrs = {\r\n            videoId: {\r\n                type: Datatypes.INTEGER,\r\n                references: {\r\n                    model: sequelize.models.Video,\r\n                    key: \"id\"\r\n                }\r\n            },\r\n            personId: {\r\n                type: Datatypes.INTEGER,\r\n                references: {\r\n                    model: sequelize.models.Person,\r\n                    key: \"id\"\r\n                }\r\n            }\r\n        };\r\n        var options = {\r\n            indexes: [\r\n                { unique: true, fields: [\"videoId\", \"personId\"], name: \"unique_VideoPeople\" }\r\n            ]\r\n        };\r\n        return sequelize.define(\"Video\", attrs, options);\r\n    };\r\n\r\nAnd in my test\r\n\r\n    describe(\"VideoPeople include\", function() {\r\n        it(\"should find people associated with a video via a video id\", function(done) {\r\n            models.Video.findById(1)\r\n                .then(function(video) {\r\n                    return video.includeMany();\r\n                })\r\n                .then(function(result) {\r\n                    expect(result).to.have.ownProperty(\"people\");\r\n                })\r\n                .catch(console.log)\r\n        });\r\n    });\r\n\r\nOnly the first query is being executed, doesn't even get to the join query.\r\n\r\n    SELECT id, name \r\n    FROM 'Videos'\r\n    AS 'Video'\r\n    WHERE 'Video'.'id' = 1;"}}