All right. 2
Welcome back. 3
The students time for us to start writing our relationship in the model right. 4
Let's call them real quick and let's see how he's done. 5
So let's go to the model country. 6
All right. 7
That's where we're going to be refining this. 8
And let's go and. 9
Right. 10
Public Function let's call it pose. 11
OK. 12
Because we're going to be pulling out the polls for a specific country right for a specific user through 13
the country model right. 14
So I hope you understand what we're doing. 15
Nah don't worry about it. 16
You got to understand it. 17
Once we do it but let's just say return this and has many true. 18
All right so there's a couple of things you've got to understand here and when we are defining this 19
relationship right now OK remember that we can choose to customize the columns write the column names 20
by default is going to pool some He's going to use some ideas are going to show you in a minute what 21
ids. 22
But there's method here. 23
Before I tell you that this method uses to model two tables right. 24
The first table that he's going to use is the pause table in this case. 25
All right. 26
And then is going to use the intermediate table where he gets the country ID from right here the user 27
in this case. 28
All right. 29
So remember we have the country Id here and that's where he gets the country ID. 30
All right. 31
And now that third parameter we can define customize we can get the country ID from here. 32
All right. 33
If you have a different name you would find it right here. 34
OK. 35
So this I.D. refers to this guy right here. 36
So if for some reason you had a different column name you would find it right here says we already have 37
this country I.D. This is where Larabee is looking for we don't have to write it down. 38
Now in order for us to to get the user id Let's go and show you right here in polls where he's going 39
now with pomes migration where his folks right here. 40
In order for us to get his User ID to customize it just in case this was different like the user ID 41
that would be the fourth column. 42
All right. 43
In the country Plass right here. 44
That would be this column right here. 45
User ID. 46
OK. 47
Just in case there were different it would be like this very similar to what we have before in other 48
relationships. 49
The only difference here is that we're using the two tables in the beginning. 50
OK. 51
First parameter the post table and the second parameter is the user table which is the intermediate 52
table which gives the country ID. 53
That's the difference here with regarding this method. 54
OK. 55
So once we get this then we can go ahead two routes and start pulling out some information. 56
So let's say for example I want to pulao the poles for the con the user that belongs to the country 57
of Dominican Republic in this case the are right. 58
And that would be me. 59
So let's find that country first. 60
OK. 61
Well first find the country OK. 62
And we're going to be using the user stable to find that country. 63
So watch this. 64
So for each this country polls see that and remember where we put that right where we created this pose 65
. 66
We go to a country that's where we have pools because we're using the intermediate table here. 67
Right. 68
We're using the pool stage was the table where we get the user ID right. 69
And then we're getting this we get in the country ID from user. 70
So this is where we are kind of relating those two tables together to pull out information. 71
All right. 72
So once we have this we can come here and return the post-Idol of specific posts right where the user 73
is from the art. 74
Let's actually include that class on top are going to be imported. 75
Remember that we have to do this on top. 76
BHB store has a little light board that we click it and then it gives option to importer or Martigny 77
on top. 78
So we're going to be importing our country. 79
All right. 80
So now when we get to when we go to use our country is going to do that for us. 81
Watch Antar and in France the post related to the user from the art which is me. 82
OK. 83
Now if we try to find the country Number four is going to find somebody else. 84
Actually I don't think we have the user related to that. 85
We have to relay the user to that. 86
So let's let's do that. 87
Don't I'm not going to leave you wondering why the network. 88
OK so let's go to our Lara Bell CMS user. 89
Pete is from country 4. 90
And if we go to a country there is USA right here and 91
all right. 92
So we would find the country number is for really 93
country with the number four and user has a country with the number four is supposed to get the title 94
of that country. 95
Let's see if we have another polls. 96
We don't have the polls so let's create one right here. 97
Pete's post just lay this 98
content. 99
Right. 100
And user ID is too. 101
So make sure you do that. 102
That's the only way you're going to get some information out of that answer. 103
There we go. 104
All right. 105
So we pull the polls from the user that belongs to the US. 106
Beautiful. 107
All right. 108
So anyway I hope you understand how this works. 109
If not just repeat the lecture again then you know try to do it yourself. 110
I'm going to actually repeat repeat it a little bit so that way for those of you that don't understand 111
they fully understand the jump to the next lecture OK. 112
So let's go back real quick and see what we did for those of you that don't understand it. 113
All right. 114
We as a country I.D. to use this we're clear on that right. 115
And we as a country is stable and we put it we put some information there in the country say we're pull 116
all the countries that this table has no foreign keys at all no other user or key user IDs country ID 117
has nothing. 118
OK. 119
Right here just the name. 120
And of course then the regular created out of data that that's it. 121
Right. 122
So now where the magic happens is in the model country because this is where we relay posts. 123
Right. 124
That's where we have the user id and on the app user we have the country ID and we are finding those 125
two there would will processing those two and attaching it to this post method. 126
All right so now Clarabelle is going to be automatically looking for the country ID. 127
All right. 128
Imagine that this is invest in this invisible. 129
You can't see a but he's there. 130
He's got to look for this country I.D. automatically in users in the Users table which is this model 131
right here is the names pay for it. 132
All right. 133
And of course all right we're going to be looking for these user id in here. 134
All right. 135
So those two are there with as you just invisible. 136
Right there. 137
They're in default mode. 138
We can define different ones. 139
Like I said before but that's how it is. 140
So this is where the magic happens. 141
All right guys. 142
Anyway thank you so much for watching this lecture and I hope you are having a lot of fun with me in 143
this course. 144
And we're going to have a lot more fun when we build applications. 145
I guarantee you that. 146
So stay tune keep motivated you're doing really good. 147
If you have any questions I'm here for you. 148
OK. 149
Thank you so much and I'll see you in the next lecture.