1 00:00:00,760 --> 00:00:07,360 Hello are welcome in this like show we are going to add a comments model. 2 00:00:07,420 --> 00:00:12,310 We be our second model in this application. 3 00:00:12,400 --> 00:00:19,040 This model is going to handle her all the comments on the post. 4 00:00:19,140 --> 00:00:24,830 So let's opened up our command line and make sure you are in Project territory. 5 00:00:24,850 --> 00:00:30,130 I'm just going to play my terminal case. 6 00:00:30,130 --> 00:00:31,480 I mean the projet there. 7 00:00:31,490 --> 00:00:37,320 GREENE So we are going to create a new model. 8 00:00:37,540 --> 00:00:44,550 So the command if you're on Windows best to run it through the bin directory we do being slash followed 9 00:00:44,560 --> 00:00:53,860 by the word Real's space generate you can just G gee if you don't want it's right to generate in four 10 00:00:54,040 --> 00:01:05,500 that wants to work I just like using the full word generate I see reals generate space he got to tell 11 00:01:05,500 --> 00:01:14,050 it what it is generating is generate in a model and I've got to give the model a name. 12 00:01:14,050 --> 00:01:17,420 I'm going to call it comment. 13 00:01:18,900 --> 00:01:21,230 Where is he. 14 00:01:21,420 --> 00:01:26,720 Capital C o double M E E N T space. 15 00:01:26,880 --> 00:01:31,800 I've got to specify the attributes that it will take. 16 00:01:31,800 --> 00:01:41,820 I want the where vesselin Leaving the comment to have a name so I'm just saying name or use up whatever 17 00:01:41,820 --> 00:01:44,040 you prefer. 18 00:01:44,050 --> 00:01:50,240 I also want to set this value to this string. 19 00:01:50,900 --> 00:01:59,840 K. also I want the body I there to be body and the body is going to be text. 20 00:02:02,780 --> 00:02:03,700 Right. 21 00:02:03,970 --> 00:02:04,840 Or. 22 00:02:05,150 --> 00:02:06,670 I want it to be. 23 00:02:06,770 --> 00:02:17,660 He paused and went as set dat two references because I want wanted to be a relationship between the 24 00:02:17,660 --> 00:02:26,220 post and the comment rights that should be read forensics. 25 00:02:26,240 --> 00:02:27,970 Yeah that's it. 26 00:02:28,190 --> 00:02:33,760 Yet when you're ready to press enter and that should generate some files. 27 00:02:33,830 --> 00:02:39,130 So these are the files that the model has generated. 28 00:02:39,130 --> 00:02:41,200 I'm going to just mention a few here. 29 00:02:41,210 --> 00:02:45,290 This one here the dbe migrate. 30 00:02:45,710 --> 00:02:47,300 Basically a migration. 31 00:02:47,320 --> 00:02:50,680 Thus the migration file to create in the comments table. 32 00:02:50,690 --> 00:02:59,420 Thus we have to run that migration to actually create the table in the database so it will include the 33 00:02:59,420 --> 00:03:00,590 name. 34 00:03:00,620 --> 00:03:08,770 You will include the time stamp as well so it includes a name as well as the time stamp and then here 35 00:03:08,910 --> 00:03:11,440 are small door comment. 36 00:03:11,450 --> 00:03:17,990 That is the outhaul comment model and then we've got testing it we're not doing any testing with this 37 00:03:17,990 --> 00:03:18,820 application. 38 00:03:18,910 --> 00:03:20,380 But who where. 39 00:03:20,400 --> 00:03:25,980 That's the where we were reference for testing we wanted test. 40 00:03:26,030 --> 00:03:28,810 RB How are the comments or why em. 41 00:03:28,820 --> 00:03:31,520 This is kinda like a database file. 42 00:03:31,520 --> 00:03:37,740 So this is a sample scanner like a sample comments for use in testing for it. 43 00:03:37,750 --> 00:03:39,740 Tests will be used in that. 44 00:03:40,130 --> 00:03:42,890 So let's take a look at the Migration. 45 00:03:42,890 --> 00:03:53,270 Far as good to our editor here at least look for the dbe to click on his dbe here. 46 00:03:53,410 --> 00:03:57,280 Will she see my great book. 47 00:03:57,420 --> 00:04:02,310 Expand the migrate and as to expand this so we can see. 48 00:04:02,710 --> 00:04:04,560 So thus the file for the post. 49 00:04:04,580 --> 00:04:06,980 And this is what we've just created. 50 00:04:07,220 --> 00:04:08,030 So you can see here. 51 00:04:08,030 --> 00:04:14,000 This is what we have to run this for d table in the database to be created. 52 00:04:14,000 --> 00:04:21,450 So this is what is going to create a table called comments and is tabers going down but one column is 53 00:04:21,460 --> 00:04:23,830 going to have two columns one is going to be named. 54 00:04:24,050 --> 00:04:24,860 I was going to be. 55 00:04:24,860 --> 00:04:31,360 Body is also going to have on a column for The Post is going to be the foreign key. 56 00:04:31,660 --> 00:04:36,770 Okay this post is going to a reference to the foreign key So that's it. 57 00:04:36,770 --> 00:04:40,280 Let's go ahead and run the migration. 58 00:04:40,450 --> 00:04:50,760 The T here the T basically will create an integer into just a number to create an integer column or 59 00:04:50,770 --> 00:04:54,170 add poor PST on dust or Haiti. 60 00:04:54,410 --> 00:04:56,330 So that's an index for it. 61 00:04:56,330 --> 00:05:06,360 It also creates a foreign key constraint that points to the idea column of The Post table. 62 00:05:08,190 --> 00:05:10,650 So let's go ahead and run the migration some to. 63 00:05:10,650 --> 00:05:12,170 Going to open on my. 64 00:05:13,550 --> 00:05:14,430 Command line. 65 00:05:14,460 --> 00:05:18,990 I just come here and just typing in Been b n slash. 66 00:05:19,920 --> 00:05:24,680 Rails space the. 67 00:05:24,700 --> 00:05:25,560 B. 68 00:05:26,490 --> 00:05:29,540 Call on my Greek. 69 00:05:31,000 --> 00:05:32,310 Press Enter. 70 00:05:32,770 --> 00:05:36,220 And that should migrate the table. 71 00:05:36,220 --> 00:05:36,950 So excellent. 72 00:05:36,940 --> 00:05:38,790 The migration has been successful. 73 00:05:38,800 --> 00:05:44,600 Told us here that is my great indie concrete commines stables so he's done it. 74 00:05:44,600 --> 00:05:45,370 It tells all. 75 00:05:45,370 --> 00:05:46,490 Here is my greeter. 76 00:05:46,500 --> 00:05:51,840 We'll put a time stamp that he shows when the migration occurred. 77 00:05:51,850 --> 00:06:00,430 In kids we want to roll rails this smart enough it will only execute the migrations that have not already 78 00:06:00,430 --> 00:06:02,680 run against the current database. 79 00:06:02,720 --> 00:06:05,410 That is how we got on the Magwitch on far. 80 00:06:05,650 --> 00:06:12,850 He wouldn't run it because he knows that we've already executed that migration so we've successfully 81 00:06:12,850 --> 00:06:18,810 created the comments model going to end this lecture here in the next linked shop. 82 00:06:18,820 --> 00:06:26,450 We gained two assholes see it the model to the other parts of the application. 83 00:06:26,470 --> 00:06:28,970 Thanks for watching and bye for now.