{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/970","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/970/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/970/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/970/events","html_url":"https://github.com/sequelize/sequelize/issues/970","id":20681550,"number":970,"title":"Include by Association Alias","user":{"login":"nova706","id":1844322,"avatar_url":"https://avatars.githubusercontent.com/u/1844322?v=3","gravatar_id":"","url":"https://api.github.com/users/nova706","html_url":"https://github.com/nova706","followers_url":"https://api.github.com/users/nova706/followers","following_url":"https://api.github.com/users/nova706/following{/other_user}","gists_url":"https://api.github.com/users/nova706/gists{/gist_id}","starred_url":"https://api.github.com/users/nova706/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nova706/subscriptions","organizations_url":"https://api.github.com/users/nova706/orgs","repos_url":"https://api.github.com/users/nova706/repos","events_url":"https://api.github.com/users/nova706/events{/privacy}","received_events_url":"https://api.github.com/users/nova706/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/question","name":"question","color":"02d7e1"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2013-10-08T14:17:05Z","updated_at":"2015-08-27T17:19:11Z","closed_at":"2013-11-19T11:23:27Z","body":"As documented, you cannot eagerly load (include) an association via its alias when using a finder:\r\n\r\n> \"If an association is aliased (using the as option), you must specify this alias when including the model.\"\r\n\r\nThis makes it difficult to construct a finder when the query is coming from a restful client. The client would have to send the name of the model and the alias name in order for the server to perform the include in the query and the client would therefore need to know details of the data model which it should not.\r\n\r\nI assume since the associations and there aliases are defined with the models, it should not be too difficult to perform a lookup when provided a string value to match an alias to its defined association. If that is true, it would be possible to perform a query to find an object and include its association via the association's alias.\r\n\r\nWhat I would like to do is this:\r\n```javascript\r\nContact.hasMany(PhoneNumber, {as: 'phoneNumbers'});\r\n\r\nContact.find({\r\n    where: { id: someId },\r\n    include: [ 'phoneNumbers' ]\r\n});\r\n```\r\n\r\nAs a note, I am using the Odata v3 standard on the client side and interpreting on the server to construct the finder."},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/135497288","html_url":"https://github.com/sequelize/sequelize/issues/970#issuecomment-135497288","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/970","id":135497288,"user":{"login":"schovi","id":11453,"avatar_url":"https://avatars.githubusercontent.com/u/11453?v=3","gravatar_id":"","url":"https://api.github.com/users/schovi","html_url":"https://github.com/schovi","followers_url":"https://api.github.com/users/schovi/followers","following_url":"https://api.github.com/users/schovi/following{/other_user}","gists_url":"https://api.github.com/users/schovi/gists{/gist_id}","starred_url":"https://api.github.com/users/schovi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schovi/subscriptions","organizations_url":"https://api.github.com/users/schovi/orgs","repos_url":"https://api.github.com/users/schovi/repos","events_url":"https://api.github.com/users/schovi/events{/privacy}","received_events_url":"https://api.github.com/users/schovi/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T17:19:11Z","updated_at":"2015-08-27T17:19:11Z","body":"Its been 2 years since last post, but I am new there and this is really annoing to write almost whole association again and again. I am long time developer of Rails, where each association has exactly one name and that is all. I dont understand, why association have to be declared by model and some name (alias).\r\nWhy associations cant be just map of alias pointing to some definition. It is larger configuration, because you have to declare each one, but usage `include: ['subcategory', 'category]` across whole app will save lot of pain.\r\n\r\n```javascript\r\n{\r\n  associations:  {\r\n    subcategory: () => Lesson.belongsTo(models.Subcategory, { foreignKey: \"subcategory_id\"}),\r\n    category: () => Lesson.belongsTo(models.Category, {foreignKey: \"category_id\"}),\r\n    lessonContents: () => Lesson.hasMany(models.LessonContent, {foreignKey: \"lesson_id\"}),\r\n    validLessonContent: () =>Lesson.hasOne(models.LessonContent.scope('valid'), {foreignKey: \"lesson_id\"})\r\n  }\r\n}\r\n```\r\nI am just curious and except this Sequelize is really awesome project and save us lot of time :)"}}