{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/2816","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/2816/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/2816/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/2816/events","html_url":"https://github.com/sequelize/sequelize/issues/2816","id":53216094,"number":2816,"title":"Confused about M:M hasMany","user":{"login":"memelet","id":22981,"avatar_url":"https://avatars.githubusercontent.com/u/22981?v=3","gravatar_id":"","url":"https://api.github.com/users/memelet","html_url":"https://github.com/memelet","followers_url":"https://api.github.com/users/memelet/followers","following_url":"https://api.github.com/users/memelet/following{/other_user}","gists_url":"https://api.github.com/users/memelet/gists{/gist_id}","starred_url":"https://api.github.com/users/memelet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/memelet/subscriptions","organizations_url":"https://api.github.com/users/memelet/orgs","repos_url":"https://api.github.com/users/memelet/repos","events_url":"https://api.github.com/users/memelet/events{/privacy}","received_events_url":"https://api.github.com/users/memelet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-01T09:05:27Z","updated_at":"2015-01-02T16:50:00Z","closed_at":null,"body":"I have had a m:m working as:\r\n```\r\n  Roles.hasMany(models.Users)\r\n  Users.hasMany(models.Roles)\r\n```\r\n\r\nSince I want to grab the user's roles I wanted an alias so first I tried:\r\n```\r\n  Roles.hasMany(models.Users, {as: \"users\"})\r\n  Users.hasMany(models.Roles, {as: \"roles\"\"})\r\n```\r\nBut this yielded:\r\n```\r\nError: Cyclic dependency found. 'Roles' is dependent of itself.\r\nDependency Chain: Roles -> Users => Roles\r\n    at visit (/Users/bkaplan/si/vi-security-users/node_modules/sequelize-extra/node_modules/sequelize/node_modules/toposort-class/toposort.js:74:27)\r\n    at /Users/bkaplan/si/vi-security-users/node_modules/sequelize-extra/node_modules/sequelize/node_modules/toposort-class/toposort.js:96:25\r\n```\r\n\r\nAfter reading the docs closer I see that through is required when using an alias. But still this error message is a bit opaque. \r\n\r\nSo I next tried:\r\n```\r\n  Roles.hasMany(models.Users, {as: \"users\", through: \"Roles_Users\"})\r\n  Users.hasMany(models.Roles, {as: \"roles\", through: \"Roles_Users\"})\r\n```\r\nBut this yielded:\r\n```\r\nUncaught exception: [RangeError: Maximum call stack size exceeded]\r\n```\r\nWith no other stack trace.\r\n\r\nIs there something basic I am missing? (Assuming this is enough context)"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/68541265","html_url":"https://github.com/sequelize/sequelize/issues/2816#issuecomment-68541265","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/2816","id":68541265,"user":{"login":"memelet","id":22981,"avatar_url":"https://avatars.githubusercontent.com/u/22981?v=3","gravatar_id":"","url":"https://api.github.com/users/memelet","html_url":"https://github.com/memelet","followers_url":"https://api.github.com/users/memelet/followers","following_url":"https://api.github.com/users/memelet/following{/other_user}","gists_url":"https://api.github.com/users/memelet/gists{/gist_id}","starred_url":"https://api.github.com/users/memelet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/memelet/subscriptions","organizations_url":"https://api.github.com/users/memelet/orgs","repos_url":"https://api.github.com/users/memelet/repos","events_url":"https://api.github.com/users/memelet/events{/privacy}","received_events_url":"https://api.github.com/users/memelet/received_events","type":"User","site_admin":false},"created_at":"2015-01-02T16:50:00Z","updated_at":"2015-01-02T16:50:00Z","body":"No, just the error. Also I just hacked sequelize-hierarchy to depend on sequelize#master and it too generates this error when using belongsToMany. eg, from modelExtends.js\r\n\r\n```\r\n                this.belongsToMany(this, {\r\n\t\t\tas: options.ancestorsAs,\r\n\t\t\tforeignKey: options.throughKey,\r\n\t\t\tthrough: options.through\r\n\t\t});\r\n```"}}