Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Last active July 1, 2020 11:14
Show Gist options
  • Select an option

  • Save kianaditya/759511024ffd100c5796d1e7bd367c80 to your computer and use it in GitHub Desktop.

Select an option

Save kianaditya/759511024ffd100c5796d1e7bd367c80 to your computer and use it in GitHub Desktop.
const db = require('../models')
exports.getAllPosts = async (req, res, next) => {
const allPosts = await db.Post.findAll({
attributes: ['id', 'title', 'content'],
include: [{
model: db.User,
as: 'Author',
attributes: ['firstName', 'lastName'],
}]
})
res.status(200).send(allPosts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment