[MUSIC] I showed the first iteration of our Blog App to the CEO of Acme Widget works. The one that allows you to add, post and comments and she was happy with it. However she did tell me there's one thing she forgot to discuss with us at our first meeting, so I pulled put the napkin that we wrote on at the last meeting and showed it to her. Here's what she wrote. The CEO forgot to mention during our last meeting that she'd like the name of authors to appear beside each of their posts. She'd like the same thing to happen for comments. I asked her if she wanted users to create accounts and then we could place the user name beside each of their posts or comments. And she liked that idea. So here's what we ended up with. We're going to put the author name beside the post, as well as beside each of the comments. And we're going to do this by using the username. So we going to need to create a user model. Based on this feedback, I created a new ERD that includes this user entity. Notice that I created a one to many relationship between users and posts and a one to many relationship between users and comments. That is, one user can have many posts, and many comments. So, we're going to need to migrate the database in order to include a new table for users. We're also going to need to add foreign key attributes to both the post and comments tables. Let's created the migrations that take care of these things. We'll start by generating a scaffold for users. So, we're going to have a user model with a first name that's a string and a last name that's a string. Next, let's create a migration for adding the foreign key of a user to the post table. So, I've got add user ID to posts. And I'm going to go ahead and add on the next line, user:references. So this will indicate that this is going to be a foreign key, and so this created that migration, and I'm going to do the same thing, for comments, and then I'm going to continue onto the next line so that's why I'm putting this backslash. And then I want to type again user:references and this is going to create these two migrations. By the way, you don't have to put the user:references on a second line if you just want to add a space. And add it to the end of the rails, generate migration command it'll also work by doing it that way. Let's take a look at the migrations that were created. Back in our editor go to db under migrate you'll see the new migrations are now there. Here's the one for creating a new user model. And then we've got one for adding a reference, adding a foreign key to the post table. So because I named the migration, add the user id to posts, it knows to use posts as the table and it knows to use user, and because I said references, it's going to create an index, and it knows that it's a foreign key. And we'll see the same thing was done for comments. The only thing left to do now is to run these migrations and let's check out the app. So we'll run rake db migrate, and we see that it created the new table, as well as adding the attributes to those two tables for posting comments. Let's make sure the schema setup properly so go to schema.rb and we'll see now that post, the post table does in fact have this foreign key for the user ID so does the comment table and that we're creating a user table as well. Let's take a look at the running app we'll type rails server and let's look at the open up our browser. Here's the running app at localhost:3000, and if you type users, you'll see that we can add new users. So the user model seems to be hooked up, and functioning, If we go back, to posts. You'll see that the posts are still there. Now there is no user listed here and there is a couple of things one has to take care of in order to make that happen. First, we are going to have to add more formal associations to our models and I'll show you how to do that in the very next video. But we're also going to have to fix up the HTML, the view itself, and we're going to have to wait until a later module on user interface in order to show you how to do that.