{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/302","repository_url":"https://api.github.com/repos/ga-wdi-exercises/project4","labels_url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/302/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/302/comments","events_url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/302/events","html_url":"https://github.com/ga-wdi-exercises/project4/issues/302","id":176437238,"number":302,"title":"Sequelize self joins","user":{"login":"TyRyanR","id":19438253,"avatar_url":"https://avatars.githubusercontent.com/u/19438253?v=3","gravatar_id":"","url":"https://api.github.com/users/TyRyanR","html_url":"https://github.com/TyRyanR","followers_url":"https://api.github.com/users/TyRyanR/followers","following_url":"https://api.github.com/users/TyRyanR/following{/other_user}","gists_url":"https://api.github.com/users/TyRyanR/gists{/gist_id}","starred_url":"https://api.github.com/users/TyRyanR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TyRyanR/subscriptions","organizations_url":"https://api.github.com/users/TyRyanR/orgs","repos_url":"https://api.github.com/users/TyRyanR/repos","events_url":"https://api.github.com/users/TyRyanR/events{/privacy}","received_events_url":"https://api.github.com/users/TyRyanR/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-12T17:39:12Z","updated_at":"2016-09-12T19:15:18Z","closed_at":null,"body":"Having trouble with \"through\" and \"as\".\r\n\r\n1) Here is my USER model. As you can see in the classMethods.associate function, I am trying to create a self join for users to have friends.. \r\n```\r\nmodule.exports = function(sequelize, DataTypes) {\r\n  var user = sequelize.define('user', {\r\n    email: DataTypes.STRING,\r\n    username: DataTypes.STRING,\r\n    password: DataTypes.STRING\r\n  }, {\r\n    hooks: {\r\n      afterValidate: function(user) {\r\n        var hash = bcrypt.hashSync((user.password, bcrypt.genSaltSync(10)));\r\n        user.password = hash;\r\n      }\r\n    }\r\n    classMethods: {\r\n      associate: function(models) {\r\n        user.hasMany(models.friendship);\r\n        user.hasMany(models.user {as: \"friends\", through: models.friendship});\r\n      }\r\n    }\r\n  });\r\n  return user;\r\n};\r\n```\r\n\r\n2) Then here in the friendships join table model, I am trying to connect to users twice, with one column being userId and one being friendID. I know I'm doing something wrong connecting the \"as\" and \"through\". Any help? Thanks\r\n\r\n```\r\n'use strict';\r\nmodule.exports = function(sequelize, DataTypes) {\r\n  var friendship = sequelize.define('friendship', {\r\n    userId: DataTypes.INTEGER,\r\n    friendId: DataTypes.INTEGER\r\n  }, {\r\n    classMethods: {\r\n      associate: function(models) {\r\n        friendship.belongsTo(models.user);\r\n        friendship.belongsTo(models.user {as: \"friend\"});\r\n      }\r\n    }\r\n  });\r\n  return friendship;\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/comments/246459153","html_url":"https://github.com/ga-wdi-exercises/project4/issues/302#issuecomment-246459153","issue_url":"https://api.github.com/repos/ga-wdi-exercises/project4/issues/302","id":246459153,"user":{"login":"superbuggy","id":17716232,"avatar_url":"https://avatars.githubusercontent.com/u/17716232?v=3","gravatar_id":"","url":"https://api.github.com/users/superbuggy","html_url":"https://github.com/superbuggy","followers_url":"https://api.github.com/users/superbuggy/followers","following_url":"https://api.github.com/users/superbuggy/following{/other_user}","gists_url":"https://api.github.com/users/superbuggy/gists{/gist_id}","starred_url":"https://api.github.com/users/superbuggy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superbuggy/subscriptions","organizations_url":"https://api.github.com/users/superbuggy/orgs","repos_url":"https://api.github.com/users/superbuggy/repos","events_url":"https://api.github.com/users/superbuggy/events{/privacy}","received_events_url":"https://api.github.com/users/superbuggy/received_events","type":"User","site_admin":false},"created_at":"2016-09-12T19:15:18Z","updated_at":"2016-09-12T19:15:18Z","body":"you'll need to include`{foreignKey: \"friend_id\"}` along with `{as: \"friend\"}` I think"}}
{"actor":{"display_login":"superbuggy"}}