Hello are welcome in this like show we are going to add a comments model.
We be our second model in this application.
This model is going to handle her all the comments on the post.
So let's opened up our command line and make sure you are in Project territory.
I'm just going to play my terminal case.
I mean the projet there.
GREENE So we are going to create a new model.
So the command if you're on Windows best to run it through the bin directory we do being slash followed
by the word Real's space generate you can just G gee if you don't want it's right to generate in four
that wants to work I just like using the full word generate I see reals generate space he got to tell
it what it is generating is generate in a model and I've got to give the model a name.
I'm going to call it comment.
Where is he.
Capital C o double M E E N T space.
I've got to specify the attributes that it will take.
I want the where vesselin Leaving the comment to have a name so I'm just saying name or use up whatever
you prefer.
I also want to set this value to this string.
K. also I want the body I there to be body and the body is going to be text.
Right.
Or.
I want it to be.
He paused and went as set dat two references because I want wanted to be a relationship between the
post and the comment rights that should be read forensics.
Yeah that's it.
Yet when you're ready to press enter and that should generate some files.
So these are the files that the model has generated.
I'm going to just mention a few here.
This one here the dbe migrate.
Basically a migration.
Thus the migration file to create in the comments table.
Thus we have to run that migration to actually create the table in the database so it will include the
name.
You will include the time stamp as well so it includes a name as well as the time stamp and then here
are small door comment.
That is the outhaul comment model and then we've got testing it we're not doing any testing with this
application.
But who where.
That's the where we were reference for testing we wanted test.
RB How are the comments or why em.
This is kinda like a database file.
So this is a sample scanner like a sample comments for use in testing for it.
Tests will be used in that.
So let's take a look at the Migration.
Far as good to our editor here at least look for the dbe to click on his dbe here.
Will she see my great book.
Expand the migrate and as to expand this so we can see.
So thus the file for the post.
And this is what we've just created.
So you can see here.
This is what we have to run this for d table in the database to be created.
So this is what is going to create a table called comments and is tabers going down but one column is
going to have two columns one is going to be named.
I was going to be.
Body is also going to have on a column for The Post is going to be the foreign key.
Okay this post is going to a reference to the foreign key So that's it.
Let's go ahead and run the migration.
The T here the T basically will create an integer into just a number to create an integer column or
add poor PST on dust or Haiti.
So that's an index for it.
It also creates a foreign key constraint that points to the idea column of The Post table.
So let's go ahead and run the migration some to.
Going to open on my.
Command line.
I just come here and just typing in Been b n slash.
Rails space the.
B.
Call on my Greek.
Press Enter.
And that should migrate the table.
So excellent.
The migration has been successful.
Told us here that is my great indie concrete commines stables so he's done it.
It tells all.
Here is my greeter.
We'll put a time stamp that he shows when the migration occurred.
In kids we want to roll rails this smart enough it will only execute the migrations that have not already
run against the current database.
That is how we got on the Magwitch on far.
He wouldn't run it because he knows that we've already executed that migration so we've successfully
created the comments model going to end this lecture here in the next linked shop.
We gained two assholes see it the model to the other parts of the application.
Thanks for watching and bye for now.