0
0
Expressframework~5 mins

Associations (hasMany, belongsTo) in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the hasMany association represent in Express ORM?
It means one record in a model can be linked to many records in another model, like one author having many books.
Click to reveal answer
beginner
What is the purpose of the belongsTo association?
It shows that a record belongs to exactly one record in another model, like a book belonging to one author.
Click to reveal answer
intermediate
How do hasMany and belongsTo work together?
They connect two models so you can find all related records easily, like getting all books for an author and the author for a book.
Click to reveal answer
beginner
In Express, where do you usually define hasMany and belongsTo?
You define them in your model files to set up relationships before querying the database.
Click to reveal answer
beginner
Why are associations like hasMany and belongsTo helpful?
They let you write simpler code to get related data without writing complex database queries.
Click to reveal answer
Which association means one record owns many records in another model?
AhasOne
BhasMany
CbelongsTo
DbelongsToMany
If a Book belongsTo an Author, what does that mean?
AA book has many authors
BBooks and authors are unrelated
CAn author belongs to a book
DA book belongs to one author
Where do you define associations like hasMany in Express?
AIn the model files
BIn the route files
CIn the view templates
DIn the server configuration
What benefit do associations provide when querying data?
AThey simplify fetching related data
BThey make queries slower
CThey remove the need for a database
DThey only work with NoSQL databases
Which association would you use if one user can have many posts?
AbelongsToMany
BbelongsTo
ChasMany
DhasOne
Explain how hasMany and belongsTo associations work together in Express models.
Think about how authors and books relate.
You got /4 concepts.
    Describe why setting up associations like hasMany and belongsTo is useful in building Express apps.
    Consider how you get all posts for a user.
    You got /4 concepts.