{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/6808","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/6808/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/6808/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/6808/events","html_url":"https://github.com/sequelize/sequelize/issues/6808","id":187483166,"node_id":"MDU6SXNzdWUxODc0ODMxNjY=","number":6808,"title":"Upsert to update the association?","user":{"login":"Abhimanyu310","id":15166376,"node_id":"MDQ6VXNlcjE1MTY2Mzc2","avatar_url":"https://avatars3.githubusercontent.com/u/15166376?v=4","gravatar_id":"","url":"https://api.github.com/users/Abhimanyu310","html_url":"https://github.com/Abhimanyu310","followers_url":"https://api.github.com/users/Abhimanyu310/followers","following_url":"https://api.github.com/users/Abhimanyu310/following{/other_user}","gists_url":"https://api.github.com/users/Abhimanyu310/gists{/gist_id}","starred_url":"https://api.github.com/users/Abhimanyu310/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Abhimanyu310/subscriptions","organizations_url":"https://api.github.com/users/Abhimanyu310/orgs","repos_url":"https://api.github.com/users/Abhimanyu310/repos","events_url":"https://api.github.com/users/Abhimanyu310/events{/privacy}","received_events_url":"https://api.github.com/users/Abhimanyu310/received_events","type":"User","site_admin":false},"labels":[{"id":28979733,"node_id":"MDU6TGFiZWwyODk3OTczMw==","url":"https://api.github.com/repos/sequelize/sequelize/labels/feature","name":"feature","color":"0b02e1","default":false},{"id":636646701,"node_id":"MDU6TGFiZWw2MzY2NDY3MDE=","url":"https://api.github.com/repos/sequelize/sequelize/labels/stale","name":"stale","color":"aaaaaa","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-11-05T07:49:34Z","updated_at":"2018-06-15T06:10:36Z","closed_at":"2017-07-18T10:56:14Z","author_association":"NONE","body":"I have a Project model and a FacultyInfo Model and the relation between the two is:\r\n\r\n```js\r\nProject.belongsTo(models.FacultyInfo, {\r\n              as : 'Faculty',\r\n              onDelete: \"CASCADE\"\r\n          })\r\n```\r\nNow when creating the models, I use a web form to submit the data and create both the models simultaneously as below:\r\n```js\r\nvar project = models.Project.create({\r\n        description: req.body.description,\r\n        url: req.body.url,\r\n        // ...\r\n        Faculty: {\r\n            name: req.body.name,\r\n            email: req.body.email,\r\n            }\r\n    }, {\r\n        include: [ {model: models.FacultyInfo, as: 'Faculty'} ]\r\n    }).then(function (task) {\r\n        //\r\n    });\r\n```\r\nAnd this works perfectly. Now I want to do an upsert in a similar way. In the above code, if I replace `create` with `upsert`, and pass in the primary key for the Project as an argument, the Project model gets updated (if found), but the FacultyInfo model does not get updated. And if the project was not found, it gets created (as expected), but the FacultyInfo model does not get created, and the faculty_id in the projects table which is the foreign key stays at `Null`\r\n\r\nMaybe, there is a way to get upsert working the way I want, but I haven't been able to find it, and I've searched so many posts on github/stackoverflow and what not.\r\n\r\nI would appreciate if someone would show me how to achieve this, or show me an alternative way to achieve this."},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/397523452","html_url":"https://github.com/sequelize/sequelize/issues/6808#issuecomment-397523452","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/6808","id":397523452,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzUyMzQ1Mg==","user":{"login":"vidit-bhatia","id":3845645,"node_id":"MDQ6VXNlcjM4NDU2NDU=","avatar_url":"https://avatars2.githubusercontent.com/u/3845645?v=4","gravatar_id":"","url":"https://api.github.com/users/vidit-bhatia","html_url":"https://github.com/vidit-bhatia","followers_url":"https://api.github.com/users/vidit-bhatia/followers","following_url":"https://api.github.com/users/vidit-bhatia/following{/other_user}","gists_url":"https://api.github.com/users/vidit-bhatia/gists{/gist_id}","starred_url":"https://api.github.com/users/vidit-bhatia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vidit-bhatia/subscriptions","organizations_url":"https://api.github.com/users/vidit-bhatia/orgs","repos_url":"https://api.github.com/users/vidit-bhatia/repos","events_url":"https://api.github.com/users/vidit-bhatia/events{/privacy}","received_events_url":"https://api.github.com/users/vidit-bhatia/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T06:10:36Z","updated_at":"2018-06-15T06:10:36Z","author_association":"NONE","body":"+1"}}
{"actor":{"display_login":"vidit-bhatia"}}