Bummer! You must be logged in to access this page.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Data Relationships with SQL and Sequelize!
You have completed Data Relationships with SQL and Sequelize!
Preview
Let's explore how to create data relationships using Sequelize by updating a simple Node.js application.
Starter Project structure
The starter project contains the following files and folders:
-
db- Contains modules responsible for interacting with the database-
models- Contains the Sequelize models for the application -
index.js- Configures the Sequelize ORM
-
-
.eslintrc.json- ESLint configuration file -
app.js- The entry point into the application. Within this file, the Sequelize models are used to create and retrieve data from the database. -
package-lock.json- Generated by npm to describe the application's exact dependency tree -
package.json- npm configuration file
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
All right, let's explore how to create
data relationships using Sequelize by
0:05
updating a simple Node.js application.
0:10
To get started and follow along, download
the project files with this video, and
0:12
open them in your preferred text editor,
I'm using Visual Studio Code.
0:16
As you follow this course,
you'll make changes to the app.js file,
0:20
and the movie.js, and
person.js files in the db/models folder.
0:25
Be sure to review the teachers notes with
this video to learn more about what's
0:29
included in the project files.
0:33
The project contains two models,
person and movie.
0:34
To start with, neither model
has any relationships defined,
0:39
we'll do that part soon.
0:42
To run the application, install the
necessary dependencies in your terminal or
0:44
console by running
the command `npm install`.
0:49
After the dependencies finish
downloading and installing,
0:53
run `npm start` to start the application.
0:56
You'll notice that as
you build the project,
0:59
several actions will occur
in a specified order.
1:02
I added these actions as console.log
statements in db/index.js and app.js.
1:05
For example, instantiating and
configuring the Sequelize object instance,
1:11
importing the database models,
configuring their associations, and so on.
1:16
This way, you'll know the step
at which each action occurs.
1:20
You'll write the functionality that
performs these actions as you follow along
1:24
in this course.
1:28
For instance, by the end, you'll
produce the following console output,
1:31
displaying data returned
from the database, and
1:36
create database tables that
looks similar to this.
1:40
All right, now you're ready to define
data relationships for the person and
1:46
movie models.
1:51
Then update the database with records
that make use of the data relationships,
1:52
and finally,
retrieve related data from the database.
1:57
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up