Skip to content

Instantly share code, notes, and snippets.

@DesignByOnyx
Created September 20, 2019 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DesignByOnyx/abad3ea8385c53589f85060fd0beab97 to your computer and use it in GitHub Desktop.
Save DesignByOnyx/abad3ea8385c53589f85060fd0beab97 to your computer and use it in GitHub Desktop.
const { tags, ...blogPost } = {
"title": "My first blog post",
"body": "...",
"tags": [
{ "text": "sequelize" },
{ "text": "feathersjs" },
{ "text": "many-to-many" }
]
};
const newPost = db.create('blog_posts', blogPost);
const newTags = db.createMany('tags', tags);
const blogPostTags = newTags.map(tag => {
return {
tag_id: tag.id,
blog_post_id: newPost.id
};
});
db.createMany('blog_post_tags', blogPostTags);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment