Skip to content

Instantly share code, notes, and snippets.

@ralyodio
Created June 14, 2015 05:17
Show Gist options
  • Save ralyodio/9be6b15ad846b7a2cc10 to your computer and use it in GitHub Desktop.
Save ralyodio/9be6b15ad846b7a2cc10 to your computer and use it in GitHub Desktop.
thinky hasAndBelongsToMany
ctrl.post = function *(next){
var data = this.request.body;
var tagIds = data.tags.map(tag => {
return tag.id;
});
delete data.tags;
var post = new Post(data);
post.tags = tagIds;
var newPost = yield post.saveAll(); //save joins
var result = yield Post.get(newPost.id).getJoin({ tags: true });
this.body = result;
yield next;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment