Skip to content

Instantly share code, notes, and snippets.

@chovy chovy/controller.js
Created Jun 14, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.