- Fork and clone this repository to your
Development
folder.
-
Create a model for an author, with a
name
field. -
Define the relationships in the
post
model. An author has many posts. -
Create
routes
andcontrollers
for theauthor
model. -
Move the
post
create route and controller to theauthor
routes and controllers. -
In the post create function, Do the 3 steps:
- Add the
authorId
toreq.body
. - Create the
post
. - Add this created
post
in theposts
array in theauthor
model usingpush
.
- Add the
-
In the
author
s get route, use thepopulate
method so that fetchingauthors
will fetch the list ofposts
he has. -
In the
post
get route, make sure when fetchingposts
, we get theauthor
object with eachpost
.
- Create a model for a
tag
with aname
field. - Define the relationships in
post
model. Apost
has manytags
. - Define the relationships in
tag
modeltags
belongs to manyposts
. - Create a route for adding a
tag
for apost
in theposts
routes file. - Create the
tagAdd
function and get thetag
id from the req params. - Find the
post
usingfindByIdAndUpdate
then insert thetag
usingpush
. - Find the
tag
usingfindByIdAndUpdate
then insert thepost
usingpush
. - In the
posts
get route, usepopulate
so that fetching posts will get us thetags
added to thispost
. - In the
tags
get route, do the same so fetching atag
will get us theposts
related to thispost
.