Hi welcome back to the students in this lecture here we're going to be learning about another type of 2
relationship has many true relationship. 3
Now this relationship allow us so provides a convenient shortcut for access distant relationships relationships 4
via an intermediary relation. 5
So for example we can have a user stable a post table and of course we can also have a country stable 6
. 7
Right. 8
And let's say the user belongs to a country of homeport a week or something like that right. 9
And we want to find out through appose not through the user but through another relay to another table 10
where is a user from we can do this we has many true relation. 11
And let me just show you real quick. 12
OK. 13
So we had to find out to another table about our relationship for a specific model. 14
In this case when we find out that really the country for a user through the post table or right to 15
an intermediate table. 16
All right. 17
So the first thing that we need to do is we need to set some type of route. 18
Right. 19
We need to make sure that when the user comes in the right becomes the through a route that we can check 20
right. 21
We can say okay we get the first parameter and we can say 22
Let me see if we can find the user country. 23
OK I like this. 24
There we go. 25
I think that makes sense. 26
And what we want to do. 27
All right. 28
All right. 29
If not we'll change it. 30
So we'll leave this like is now. 31
But before we do we getting to routes any delay before we start pulling information let's actually create 32
one of the most important things which is the migration. 33
We need to have our country stable and we also need to have a column in the user table for country ID 34
on. 35
All right we're not going to be accessing the country from the users table. 36
All right. 37
We can it's very easy to do but that could get really messy. 38
We want things clean. 39
One we want we don't want to have you know forging IDs all over the place. 40
All right so let's actually create a migration Let's call this BHB or send make let's just make the 41
model right away because we're going to need a country with a migration of countries. 42
All right. 43
Once we have that now we need to add a country Id table to user. 44
So let's create a migration for that as well. 45
So BHP areason make migration. 46
And then we're going to say this is the description we don't have to write it like this but it makes 47
a lot of a lot of sense and Clarabell recommends for us to write the description of our migration like 48
this add country Id call them 49
two countries. 50
I mean two users and we're going to be dealing with the table users of course and we go mentor. 51
Whoops 52
. 53
It didn't go through. 54
There we go. 55
Enter now is created. 56
All right. 57
Perfect. 58
So now let's make sure that it's good. 59
Let's go to our migration and let's finish it up by users here. 60
We're going to create a column. 61
It's going to be a integer actually. 62
And you know me country ID. 63
OK. 64
All right the method here to drop it just in case let's just get the object first right. 65
And then drop colon and is going to be country. 66
We go. 67
All right perfect. 68
So now let's go and to the countries and also create 69
a name column for it. 70
All right. 71
Beautiful. 72
Now it's migrated Cortis and migrate Antar. 73
All right both tables table and column migrated. 74
Let's refresh. 75
We have the countries table here. 76
Let's just pull some countries in their right mind and put your PR and 77
what else would keep rushing there. 78
U.S. 79
India 80
Israel 81
Canada 82
United Kingdom 83
right. 84
All right. 85
You guys are from too many countries I can guess. 86
All of you are right. 87
And Jose Rodriguez a lot of countries out there. 88
So anyway so now that we have a country let's actually go to the users table and make Edwin díaz from 89
the air. 90
All right. 91
We'll make him from that country where is the country right here. 92
So does ID number one let's make Peter from the U.S. I think I actually was a U.S. 93
You say right here number four. 94
OK 95
. 96
All right cool. 97
All right so I think I want you to add that did. 98
I want you to digest this information. 99
Remember we started with routes. 100
All right we create a small route here. 101
Then we started creating the migrations. 102
OK the countries table and we adding a column called CONTOURI ID to the users table. 103
So do that and I'll see you in the next lecture. 104
Thank you