From 5d7273167349c4f0167cf4d0e2a332497bf7a0e0 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 25 Nov 2016 04:02:02 +0100 Subject: [PATCH] =?UTF-8?q?deleting=20an=20article,=20removes=20the=20arti?= =?UTF-8?q?cle=20from=20the=20author=E2=80=99s=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/articles.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/controllers/articles.js b/controllers/articles.js index 0985eec..b886a8e 100644 --- a/controllers/articles.js +++ b/controllers/articles.js @@ -42,6 +42,10 @@ router.get('/:id', function(req,res){ }); router.delete('/:id', function(req, res){ + Author.findOne({'articles._id':req.params.id}, function(err, author){ + author.articles.id(req.params.id).remove(); + author.save(); + }); Article.findByIdAndRemove(req.params.id, function(){ res.redirect('/articles'); });