Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Route **/
- router.get("/",(req,res,next) => {
- var posts = models.Post.findAll({
- attributes: ["id","title"],
- include: [{
- model: models.Category,
- as: "Categories",
- attributes: ["id","title"]
- }]
- })
- .then( posts => {
- res.json(posts);
- })
- .catch(function(err){
- console.log(err);
- res.status(400).send({error: "Bad Request - Malformed request."});
- });
- });
- /** Result output
- [
- {
- "id": 1,
- "title": "Test Post",
- "Categories": [
- {
- "id": 1,
- "title": "Test Category",
- "PostsCategories": {
- "post_id": 1,
- "category_id": 1
- }
- }
- ]
- }
- ]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement