1
00:00:00,460 --> 00:00:08,039
Let's see how we are going to model the data for this application inside the model.

2
00:00:08,050 --> 00:00:18,640
And for each I have added a file for each folder and I have renamed the models to model and I will provide

3
00:00:18,640 --> 00:00:20,950
the finance source code for you.

4
00:00:20,950 --> 00:00:27,160
But the most important here is how we are going to relate the models together.

5
00:00:27,160 --> 00:00:29,500
So let's start with the user.

6
00:00:29,500 --> 00:00:34,270
For the user, first step is that I require the mongoose.

7
00:00:34,270 --> 00:00:41,740
Next step is I need to create what is called schema and schema represents the blueprint of which we

8
00:00:41,740 --> 00:00:47,560
can create instances of objects after we compile the schema to model.

9
00:00:47,650 --> 00:00:56,920
So for user, we have this field full name and it's a required field and next is email of the user,

10
00:00:56,920 --> 00:00:59,530
which is also required password.

11
00:00:59,530 --> 00:01:02,290
The profile image of the user.

12
00:01:02,290 --> 00:01:07,420
And this I'm going to be optional and the cover image of the user.

13
00:01:07,510 --> 00:01:13,930
So this cover image represents, for example, if you go to the user profile page and the background,

14
00:01:13,930 --> 00:01:16,540
you're going to see an image being used.

15
00:01:16,540 --> 00:01:24,010
And here I added what is called timestamp, and this one is going to help us to automatically add a

16
00:01:24,010 --> 00:01:24,520
date.

17
00:01:24,520 --> 00:01:33,070
A document was created or a date a document was updated, and next step is I compiled the schema to

18
00:01:33,070 --> 00:01:40,510
form a module and in here I pass in a variable called user, and then the user schema and I go back

19
00:01:40,510 --> 00:01:41,620
my model.

20
00:01:41,650 --> 00:01:48,400
So up to this point, there is no relationship in here, and the next module is going to be the pose

21
00:01:48,400 --> 00:01:49,240
for pose.

22
00:01:49,240 --> 00:01:50,410
These are the fields.

23
00:01:50,410 --> 00:01:56,230
We need the title of the post description and then the category.

24
00:01:56,230 --> 00:02:02,020
And I provide that, the accepted category and the image of the post.

25
00:02:02,020 --> 00:02:06,250
And lastly, I compile the schema to form model.

26
00:02:06,280 --> 00:02:14,080
Next I'm going to be the command and for commands we need the user who is creating the command and the

27
00:02:14,080 --> 00:02:15,940
message about the command.

28
00:02:15,940 --> 00:02:23,350
So for this we are using the reference with the last property we need to add is called ref, meaning

29
00:02:23,350 --> 00:02:29,830
that which model we referencing and we are referencing the user module.

30
00:02:30,160 --> 00:02:33,040
All right, so let's look at the relationship between them.

31
00:02:33,040 --> 00:02:34,600
Let's start with the user.

32
00:02:34,600 --> 00:02:40,240
Remember, a user can create many posts that is one to many relationship.

33
00:02:40,240 --> 00:02:43,690
So here we are going to add a property called post.

34
00:02:43,780 --> 00:02:51,850
And when I build an array and inside this array of post, we can decide how we are going to push the

35
00:02:51,850 --> 00:02:53,020
post into it.

36
00:02:53,020 --> 00:02:54,640
And we have two ways.

37
00:02:54,640 --> 00:03:02,680
One is using the embedded and that is using the entire post into this array or by reference, meaning

38
00:03:02,680 --> 00:03:08,680
we are going to save only the IDs of the post and that is what we are going to use.

39
00:03:08,680 --> 00:03:16,270
So inside here I'll provide objects that provide a type, the type or there is going to be a special

40
00:03:16,270 --> 00:03:23,770
type called mongoose Dart schema DART types dot object ID.

41
00:03:23,860 --> 00:03:28,570
The next property is that we need to provide which model are we referencing?

42
00:03:28,570 --> 00:03:32,260
And we are referencing the post model.

43
00:03:32,260 --> 00:03:39,040
And this one is going to be optional because as soon as you register you have no post being created.

44
00:03:39,220 --> 00:03:46,690
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.

45
00:03:46,780 --> 00:03:57,310
So inside the post here we are going to add a field called author or the user, so I'll make it as user.

46
00:03:57,370 --> 00:04:04,030
And this I'm going to be a single user because a post might belong to a single user.

47
00:04:04,030 --> 00:04:06,550
So I'm going to use what is called objects.

48
00:04:06,550 --> 00:04:15,760
So the type here is going to be a special type, as we did before as Mongoose, dot schema, dot types,

49
00:04:15,760 --> 00:04:27,010
dot object ID, and we are going to reference the user model and this is a required field going to be

50
00:04:27,100 --> 00:04:28,360
as true.

51
00:04:28,630 --> 00:04:33,760
So now we have related a post and then a user.

52
00:04:34,090 --> 00:04:41,110
The next relationship is post and then the comment a post will have many comments.

53
00:04:41,110 --> 00:04:46,540
So on the post schema, we are going to save all the comments.

54
00:04:46,780 --> 00:04:51,070
So going to be as we did by using the reference.

55
00:04:51,070 --> 00:04:59,680
So here provide object and a type is going to be the ID of the comments and we need to reference the.

56
00:04:59,870 --> 00:05:05,630
Comments model EIS comment and that is it about that.

57
00:05:05,630 --> 00:05:12,740
Now we have the user and then the comment bout for the comments and users.

58
00:05:12,740 --> 00:05:18,380
Well, you can add that one, meaning that if you go to your profile page, you want to see all the

59
00:05:18,380 --> 00:05:20,360
comments that you have created.

60
00:05:20,570 --> 00:05:24,590
But I think this one is not the ideal way, right?

61
00:05:24,800 --> 00:05:27,230
But if want to do that one, why not?

62
00:05:27,230 --> 00:05:30,230
You can add it by copying this one.

63
00:05:30,410 --> 00:05:34,250
And here I'll make use of comments.

64
00:05:35,620 --> 00:05:40,990
And I would change this one to comment model.

65
00:05:40,990 --> 00:05:43,390
And that is it and that is it.

66
00:05:43,420 --> 00:05:44,140
All right.

67
00:05:44,140 --> 00:05:48,280
So it is how we can model the data for our project.

68
00:05:48,280 --> 00:05:51,640
Then this video, let's get started with the users.

