WEBVTT

00:00.210 --> 00:00.600
All right.

00:00.600 --> 00:02.330
Moving on to like this.

00:02.400 --> 00:08.640
So we've seen now users photos and comments and likes are a little bit similar.

00:08.670 --> 00:16.470
They are like the comments schema because when we think about how likes work on Instagram at least you

00:16.470 --> 00:19.130
like something you like that particular photo.

00:19.130 --> 00:22.230
Let's say it's corresponding to that photo.

00:22.260 --> 00:24.120
We need to have an association there.

00:24.540 --> 00:31.980
But then there's also the association between me the person liking it and the like itself.

00:32.280 --> 00:38.940
And that might not matter if we allowed for infinite likes you know anybody could like something as

00:38.940 --> 00:43.340
many times as they wanted to say it was a button that clicked and it just kept going every time I clicked

00:43.340 --> 00:43.760
it.

00:43.890 --> 00:48.670
We could get away with not storing user information with a like.

00:48.900 --> 00:53.850
But even then it might be nice to see how many times somebody had like something or how many likes you

00:53.850 --> 00:55.500
know in general.

00:55.500 --> 00:59.240
How often do I click the Like button compared to somebody else.

00:59.400 --> 01:04.020
It might be it might help us figure out who's a bot like on Instagram that's a big problem actually

01:04.020 --> 01:11.430
are these bots that people write they go and just like photos like things all the time create comments

01:11.430 --> 01:12.840
that are just cookie cutter.

01:13.200 --> 01:18.150
It's kind of frustrating actually if you're a photographer because you know you'll post something and

01:18.150 --> 01:24.480
then you get excited that you have you know 100 people who liked it and it turns out a lot of them are

01:24.480 --> 01:24.910
bought.

01:24.930 --> 01:28.760
If you actually go try and look at them they don't have any photos post really.

01:28.860 --> 01:30.750
They always comment the same thing.

01:30.750 --> 01:38.190
Long story short in this giant dataset here I actually coded in some bots that will be working with

01:38.460 --> 01:44.130
basically people who aren't in search who aren't creating much stuff they're not posting many photos

01:44.400 --> 01:49.470
but they are liking a lot of things and commenting on the same thing all the time.

01:49.470 --> 01:51.210
Anyway back to likes.

01:51.630 --> 01:59.310
It's going to look like this will have a user ID and a photo ID and a created app so our user ID is

01:59.310 --> 02:07.720
going to refer to a user's ID and a photo ID refer to a photo ID and there is really nothing else.

02:07.790 --> 02:10.330
Is no information being stored there.

02:10.440 --> 02:15.030
You know aside from the date or the time it was created when the like happened.

02:15.030 --> 02:17.030
But what else is there in store.

02:17.080 --> 02:23.430
You know maybe Instagram is doing stuff like whether it was liked from the web version versus the iOS

02:23.430 --> 02:24.120
version.

02:24.180 --> 02:29.810
Maybe they're storing you know other information here possibly but for us this is the basics.

02:29.820 --> 02:35.530
We just need a user ID and a photo ID and every time no photo is liked by a different user.

02:35.580 --> 02:40.300
We get a new like just like this with the user id and photo ID.

02:40.470 --> 02:42.030
So we'll start by coding this.

02:42.030 --> 02:45.610
You might have noticed that I didn't add an ID to the likes.

02:45.650 --> 02:47.060
Explain why in just a second.

02:47.340 --> 02:50.480
But let's start by creating our table.

02:50.770 --> 02:53.710
So we have create table like this.

02:54.390 --> 02:56.960
And don't forget the semi-colon.

02:57.120 --> 03:05.470
We've got a user ID and a photo ID and are created at headstart was created at we often neglect it.

03:05.520 --> 03:08.730
Time stamp the default now.

03:09.210 --> 03:09.600
OK.

03:09.600 --> 03:10.640
Nice and easy.

03:10.920 --> 03:13.790
User ID is just an integer.

03:14.200 --> 03:16.850
I don't want it to be empty.

03:16.860 --> 03:19.040
Same thing for photo ID.

03:20.320 --> 03:32.830
But then we need to set up our foreign key constraints for key user id references user's ID comma and

03:32.900 --> 03:35.430
other foreign key.

03:35.430 --> 03:41.580
This time photo ID references photos Id.

03:42.590 --> 03:47.400
OK so now let's address why we don't have an ID here.

03:47.400 --> 03:50.370
And the main reason is that we don't need an ID.

03:50.400 --> 03:53.800
We're not going to be referring to like anywhere else.

03:53.930 --> 04:00.570
If we were it would be good to add an ID there maybe but we're not having any table store information

04:00.570 --> 04:01.350
about likes.

04:01.350 --> 04:07.590
The other thing you might be wondering about is how do we ensure that you know there's only one like

04:07.600 --> 04:08.550
per user.

04:08.550 --> 04:10.290
Is there a way to do that in the database.

04:10.290 --> 04:18.030
Because right now if I did this I could just insert let's say my user ID is one and a photo ID is one

04:18.390 --> 04:23.430
I could insert a like with the user id one photo ID one and then insert it again and again and again.

04:23.760 --> 04:25.200
And there's nothing stopping that.

04:25.200 --> 04:30.480
So what we really want to say is we want a unique combination of the two.

04:30.570 --> 04:35.880
There can only be one instance of every combination and there's actually a way of saying that we haven't

04:35.880 --> 04:45.630
seen it but you can do this primary key and then we can just say use your ID comma photo ID.

04:45.690 --> 04:52.350
So what this will do is basically not allow you to insert to you know like that are exactly the same

04:52.650 --> 04:58.800
the same user ID and the same photo ID and I'll demonstrate that if you feel confident if you trust

04:58.800 --> 05:00.800
me there you can skip move on.

05:00.820 --> 05:02.260
We're done with the ski mask here.

05:02.410 --> 05:04.240
Let's just make sure that it runs.

05:04.290 --> 05:06.940
I don't have any syntax errors of course.

05:07.360 --> 05:08.050
OK.

05:08.320 --> 05:08.880
It does.

05:09.060 --> 05:12.640
But if you'd like to see me try it out like the last couple of videos.

05:12.640 --> 05:13.730
I'll do that now.

05:14.110 --> 05:21.280
So if you're still with me I'm going to do is take these photos and these users I'm going to have some

05:21.280 --> 05:22.100
of them like them.

05:22.240 --> 05:28.320
So let's take a blue user id one and that first photo she created it.

05:28.330 --> 05:29.270
That doesn't matter.

05:29.290 --> 05:31.180
You can like your own photo on Instagram.

05:31.360 --> 05:33.000
So will insert into likes

05:39.550 --> 05:43.610
and we have user id come a photo ID.

05:44.770 --> 05:51.500
So the first one will be one coming one so I'm inserting blue is liking this photo.

05:51.700 --> 05:53.900
And then let's have Charlie Brown also like it.

05:54.070 --> 05:59.260
So that would be a weps to come in one.

05:59.740 --> 06:05.710
And then we've got the next photo here which has a photo idea of two not this.

06:05.740 --> 06:07.820
Remember this is the user who created it.

06:08.050 --> 06:10.270
But this has an idea of two.

06:10.630 --> 06:12.890
So let's say blue also likes that one.

06:13.000 --> 06:19.810
So blue idea if one likes photo ID two and she likes photo ID of three.

06:19.870 --> 06:27.200
And then what say I have used already three I like photo with idea of three.

06:27.910 --> 06:28.480
OK.

06:29.140 --> 06:31.400
So let's start there.

06:32.650 --> 06:33.100
We run it.

06:33.100 --> 06:34.360
It works.

06:34.390 --> 06:36.220
There shouldn't be any problems at this point.

06:36.400 --> 06:44.100
But now if I try and do this insert into likes user id come a photo ID values.

06:44.170 --> 06:45.800
And I do one comma one.

06:45.940 --> 06:47.170
Well that's not that.

06:47.170 --> 06:51.060
There you go one come one which already is in there blue.

06:51.490 --> 06:52.960
User ID one.

06:53.470 --> 06:55.250
And then this photo.

06:55.330 --> 07:03.040
And while Bob 5:53 with idea of one we already have that like that if I try it you can see it duplicate

07:03.040 --> 07:06.000
entry 1 dash 1 for key primary.

07:06.220 --> 07:11.980
So the way it does it is basically combined to to keep track of the combination like that the dash between

07:11.980 --> 07:12.360
it.

07:12.370 --> 07:13.920
So that's pretty much it.

07:14.080 --> 07:18.560
I will copy what we just did an ad a note here.

07:19.030 --> 07:29.720
If you're looking at these notes later just saying it won't work because of primary key constraint and

07:29.740 --> 07:30.750
are commented out as well.

07:30.760 --> 07:32.500
We don't want to run that every time.

07:32.500 --> 07:33.190
Great.

07:33.200 --> 07:38.710
And next up we're moving on to a fun one which is relationships following followers all this stuff.
