Let's see how we are going to model the data for this application inside the model.
And for each I have added a file for each folder and I have renamed the models to model and I will provide
the finance source code for you.
But the most important here is how we are going to relate the models together.
So let's start with the user.
For the user, first step is that I require the mongoose.
Next step is I need to create what is called schema and schema represents the blueprint of which we
can create instances of objects after we compile the schema to model.
So for user, we have this field full name and it's a required field and next is email of the user,
which is also required password.
The profile image of the user.
And this I'm going to be optional and the cover image of the user.
So this cover image represents, for example, if you go to the user profile page and the background,
you're going to see an image being used.
And here I added what is called timestamp, and this one is going to help us to automatically add a
date.
A document was created or a date a document was updated, and next step is I compiled the schema to
form a module and in here I pass in a variable called user, and then the user schema and I go back
my model.
So up to this point, there is no relationship in here, and the next module is going to be the pose
for pose.
These are the fields.
We need the title of the post description and then the category.
And I provide that, the accepted category and the image of the post.
And lastly, I compile the schema to form model.
Next I'm going to be the command and for commands we need the user who is creating the command and the
message about the command.
So for this we are using the reference with the last property we need to add is called ref, meaning
that which model we referencing and we are referencing the user module.
All right, so let's look at the relationship between them.
Let's start with the user.
Remember, a user can create many posts that is one to many relationship.
So here we are going to add a property called post.
And when I build an array and inside this array of post, we can decide how we are going to push the
post into it.
And we have two ways.
One is using the embedded and that is using the entire post into this array or by reference, meaning
we are going to save only the IDs of the post and that is what we are going to use.
So inside here I'll provide objects that provide a type, the type or there is going to be a special
type called mongoose Dart schema DART types dot object ID.
The next property is that we need to provide which model are we referencing?
And we are referencing the post model.
And this one is going to be optional because as soon as you register you have no post being created.
So the next step is that let's get back to the posts and let's see how we are going to relate the user.
So inside the post here we are going to add a field called author or the user, so I'll make it as user.
And this I'm going to be a single user because a post might belong to a single user.
So I'm going to use what is called objects.
So the type here is going to be a special type, as we did before as Mongoose, dot schema, dot types,
dot object ID, and we are going to reference the user model and this is a required field going to be
as true.
So now we have related a post and then a user.
The next relationship is post and then the comment a post will have many comments.
So on the post schema, we are going to save all the comments.
So going to be as we did by using the reference.
So here provide object and a type is going to be the ID of the comments and we need to reference the.
Comments model EIS comment and that is it about that.
Now we have the user and then the comment bout for the comments and users.
Well, you can add that one, meaning that if you go to your profile page, you want to see all the
comments that you have created.
But I think this one is not the ideal way, right?
But if want to do that one, why not?
You can add it by copying this one.
And here I'll make use of comments.
And I would change this one to comment model.
And that is it and that is it.
All right.
So it is how we can model the data for our project.
Then this video, let's get started with the users.