{"action":"closed","issue":{"url":"https://api.github.com/repos/dchester/epilogue/issues/146","repository_url":"https://api.github.com/repos/dchester/epilogue","labels_url":"https://api.github.com/repos/dchester/epilogue/issues/146/labels{/name}","comments_url":"https://api.github.com/repos/dchester/epilogue/issues/146/comments","events_url":"https://api.github.com/repos/dchester/epilogue/issues/146/events","html_url":"https://github.com/dchester/epilogue/issues/146","id":138159710,"number":146,"title":"Create an association after insert (Transactions)","user":{"login":"jansen24","id":2498157,"avatar_url":"https://avatars.githubusercontent.com/u/2498157?v=3","gravatar_id":"","url":"https://api.github.com/users/jansen24","html_url":"https://github.com/jansen24","followers_url":"https://api.github.com/users/jansen24/followers","following_url":"https://api.github.com/users/jansen24/following{/other_user}","gists_url":"https://api.github.com/users/jansen24/gists{/gist_id}","starred_url":"https://api.github.com/users/jansen24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jansen24/subscriptions","organizations_url":"https://api.github.com/users/jansen24/orgs","repos_url":"https://api.github.com/users/jansen24/repos","events_url":"https://api.github.com/users/jansen24/events{/privacy}","received_events_url":"https://api.github.com/users/jansen24/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-03T12:08:03Z","updated_at":"2016-04-11T14:04:54Z","closed_at":"2016-04-11T14:04:54Z","body":"I've recently started using Epilogue, and it's been a really useful tool to get my API set-up quickly and efficiently. However, the lack of documentation hinders my progress. I've tried looking at the source code and the test cases, but I couldn't find an answer to this question. I think there should be a clean way to do this, but I can't figure it out yet.\r\n\r\n*Problem*\r\nTo simplify the problem suppose I have the following models: `Student`, `Class`, `Student_Class`\r\n```\r\nClass.belongsToMany(Student, {through: \"Student_Class\", as: \"class\", foreignKey: \"class_id\"})\r\nStudent.belongsToMany(Class, {through: \"Student_Class\", as: \"student\", foreignKey: \"student_id\"})\r\n```\r\n\r\nA `Class` can have many `Student`s, and a `Student` can belong to many `Class`es. My models and fields are all different from this, but this is the simplest real world example I could think of. Anyway, I have the database and a login system set-up. What I want to do is this:\r\n\r\nSuppose I am a `Student` and I'm currently logged in to the system. For some reason, I have rights to create a new `Class`. I create a new `Class`. I want to automatically be a `Student` of that class.  \r\n\r\nFrom a technical perspective, this means that when the endpoint to create a new `Class` is called, there should be a hook of some sort that would create an entry in the `Student_Class` table using the ID of the currently logged in user. Supposedly, the way to do this would be a series of `before` and `after` hooks, but I'm unsure of how to set it up. I also want to be able to control when the commit will be called. I want to have the ability to gracefully control the commits and rollbacks so that I won't have problems further down the road. Basically, how do I handle Transactions? Or should I just roll out my own endpoint and use Sequelize's transactions for complicated matters?"}}