Lesson 18. Building the user model


In lesson 17, you improved your models by adding validators and instance methods. You also made your first model associations and populated data from referenced models. In this lesson, you apply some of those techniques to the user model. In doing so, you also interact with these models through their respective controllers and routes. Last, you build some forms and tables to make it easier to visualize all the data in the application.

This lesson covers

  • Creating model associations with a user model
  • Using virtual attributes
  • Implementing a CRUD structure on the user model
  • Building an index page to view all users in your database
Consider this

You have two models working with your recipe application: Subscriber and Course. You’d still like visitors to create accounts and start signing up for recipe programs. The user model is in nearly every modern application, along with a system to create, read, update, and delete (CRUD) data from the database. With the help of Mongoose, Express.js, and CRUD, your users will soon have a way to sign in to your application.

18.1. Building the user model

18.2. Adding CRUD methods to your models

18.3. Building the index page

18.4. Cleaning up your actions