{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/10282","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/10282/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/10282/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/10282/events","html_url":"https://github.com/sequelize/sequelize/issues/10282","id":392457054,"node_id":"MDU6SXNzdWUzOTI0NTcwNTQ=","number":10282,"title":"Unhandled rejection Error: Invalid value user","user":{"login":"shiqikai","id":10249745,"node_id":"MDQ6VXNlcjEwMjQ5NzQ1","avatar_url":"https://avatars1.githubusercontent.com/u/10249745?v=4","gravatar_id":"","url":"https://api.github.com/users/shiqikai","html_url":"https://github.com/shiqikai","followers_url":"https://api.github.com/users/shiqikai/followers","following_url":"https://api.github.com/users/shiqikai/following{/other_user}","gists_url":"https://api.github.com/users/shiqikai/gists{/gist_id}","starred_url":"https://api.github.com/users/shiqikai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiqikai/subscriptions","organizations_url":"https://api.github.com/users/shiqikai/orgs","repos_url":"https://api.github.com/users/shiqikai/repos","events_url":"https://api.github.com/users/shiqikai/events{/privacy}","received_events_url":"https://api.github.com/users/shiqikai/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2018-12-19T06:21:14Z","updated_at":"2018-12-19T09:42:08Z","closed_at":"2018-12-19T09:40:10Z","author_association":"NONE","body":"<!--\r\n\r\nPlease note this is an issue tracker, not a support forum.\r\nFor general questions, please use StackOverflow or Slack.\r\n\r\nFor bugs, please fill out the template below.\r\n\r\n-->\r\n\r\n## What are you doing?\r\n<!-- Post a minimal, self-contained code sample that reproduces the issue, including models and associations -->\r\n\r\n```\r\nThere is an associations\r\n    User.belongsToMany(Community, { as: 'Communitys', through: communityUser })\r\n    Community.belongsToMany(User, { through: communityUser })\r\nbelow is my code:\r\n const community = await CommunityModel.getCommunityById(communityId);\r\n const user = await UserModel.findUserById(userId);\r\n community.addUser(user)\r\n\r\nIN CommunityModel:\r\nstatic async getCommunityById(id) {\r\n        return await Community.findById(id);\r\n    }\r\nIN  UserModel:\r\nstatic async findUserById(id) {\r\n        return await User.findById(id);\r\n    }\r\n```\r\n\r\n## What do you expect to happen?\r\nNo error\r\n\r\n## What is actually happening?\r\nUnhandled rejection Error: Invalid value user {\r\n  dataValues:\r\n   { id: 1,\r\n     username: 'sqk',\r\n     password: '$2a$10$yQWSBtHOiR1OcyHKSyyLEOsdajzH4hsSrx69ES/GAxOG8h5LliHZ6',\r\n     session_key: null,\r\n     phone: null,\r\n     email: null,\r\n     money: null,\r\n     city: null,\r\n     avatarUrl: null,\r\n     sex: null,\r\n     birthday: null,\r\n     lastLoginTime: null,\r\n     registerTime: 2018-12-19T04:20:11.000Z,\r\n     wxOpenid: 'test',\r\n     createdAt: 2018-12-19T04:20:11.000Z,\r\n     updatedAt: 2018-12-19T04:20:11.000Z },\r\n  _previousDataValues:\r\n   { id: 1,\r\n     username: 'sqk',\r\n     password: '$2a$10$yQWSBtHOiR1OcyHKSyyLEOsdajzH4hsSrx69ES/GAxOG8h5LliHZ6',\r\n     session_key: null,\r\n     phone: null,\r\n     email: null,\r\n     money: null,\r\n     city: null,\r\n     avatarUrl: null,\r\n     sex: null,\r\n     birthday: null,\r\n     lastLoginTime: null,\r\n     registerTime: 2018-12-19T04:20:11.000Z,\r\n     wxOpenid: 'test',\r\n     createdAt: 2018-12-19T04:20:11.000Z,\r\n     updatedAt: 2018-12-19T04:20:11.000Z },\r\n  _changed: {},\r\n  _modelOptions:\r\n   { timestamps: true,\r\n     validate: {},\r\n     freezeTableName: true,\r\n     underscored: false,\r\n     underscoredAll: false,\r\n     paranoid: false,\r\n     rejectOnEmpty: false,\r\n     whereCollection: { id: 1 },\r\n     schema: null,\r\n     schemaDelimiter: '',\r\n     defaultScope: {},\r\n     scopes: [],\r\n     indexes: [],\r\n     name: { plural: 'users', singular: 'user' },\r\n     omitNull: false,\r\n     sequelize:\r\n      Sequelize {\r\n        options: [Object],\r\n        config: [Object],\r\n        dialect: [Object],\r\n        queryInterface: [Object],\r\n        models: [Object],\r\n        modelManager: [Object],\r\n        connectionManager: [Object],\r\n        importCache: [Object],\r\n        test: [Object] },\r\n     hooks: {},\r\n     uniqueKeys: { user_wxOpenid_unique: [Object] } },\r\n  _options:\r\n   { isNewRecord: false,\r\n     _schema: null,\r\n     _schemaDelimiter: '',\r\n     raw: true,\r\n     attributes:\r\n      [ 'id',\r\n        'username',\r\n        'password',\r\n        'session_key',\r\n        'phone',\r\n        'email',\r\n        'money',\r\n        'city',\r\n        'avatarUrl',\r\n        'sex',\r\n        'birthday',\r\n        'lastLoginTime',\r\n        'registerTime',\r\n        'wxOpenid',\r\n        'createdAt',\r\n        'updatedAt' ] },\r\n  __eagerlyLoadedAssociations: [],\r\n  isNewRecord: false }\r\n    at Object.escape (D:\\project\\koa2-community\\node_modules\\sequelize\\lib\\sql-string.js:66:11)\r\n    at Object.escape (D:\\project\\koa2-community\\node_modules\\sequelize\\lib\\dialects\\abstract\\query-generator.js:934:22)\r\n    at _joinKeyValue.value.map.item (D:\\project\\koa2-community\\node_modules\\sequelize\\lib\\dialects\\abstract\\query-generator.js:2369:69)\r\n    at Array.map (<anonymous>)\r\n\r\n\r\n_Output, either JSON or SQL_\r\n\r\n\r\n__Dialect:__ mysql \r\n__Dialect version:__ XXX\r\n__Database version:__ 5.7\r\n__Sequelize version:__ 4.37.10\r\n__Tested with latest release:__ No (If yes, specify that version)\r\n\r\n\r\n**Note :** _Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template._\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/448532208","html_url":"https://github.com/sequelize/sequelize/issues/10282#issuecomment-448532208","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/10282","id":448532208,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODUzMjIwOA==","user":{"login":"shiqikai","id":10249745,"node_id":"MDQ6VXNlcjEwMjQ5NzQ1","avatar_url":"https://avatars1.githubusercontent.com/u/10249745?v=4","gravatar_id":"","url":"https://api.github.com/users/shiqikai","html_url":"https://github.com/shiqikai","followers_url":"https://api.github.com/users/shiqikai/followers","following_url":"https://api.github.com/users/shiqikai/following{/other_user}","gists_url":"https://api.github.com/users/shiqikai/gists{/gist_id}","starred_url":"https://api.github.com/users/shiqikai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shiqikai/subscriptions","organizations_url":"https://api.github.com/users/shiqikai/orgs","repos_url":"https://api.github.com/users/shiqikai/repos","events_url":"https://api.github.com/users/shiqikai/events{/privacy}","received_events_url":"https://api.github.com/users/shiqikai/received_events","type":"User","site_admin":false},"created_at":"2018-12-19T09:42:08Z","updated_at":"2018-12-19T09:42:08Z","author_association":"NONE","body":"> Yep stacktrace point to `findAll` which is called by `findById`, looks like you are accidentally passing instance (an object) instead of `id`. Try commenting or passing ids in `findById` one by one to discover the bug or add logs before passing `id` to `findById`\r\n\r\nthe log show the id is number .   I really don't know  how to fix it.  Looking for your help  eagerly 。Thanks"}}
{"actor":{"display_login":"shiqikai"}}