0
0
Flaskframework~5 mins

Many-to-many relationships in Flask - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a many-to-many relationship in databases?
It is a connection where multiple records in one table relate to multiple records in another table. For example, students can enroll in many courses, and courses can have many students.
Click to reveal answer
beginner
How do you represent a many-to-many relationship in Flask with SQLAlchemy?
You create a helper table called an association table that holds foreign keys from both related tables. This table links the two tables without extra data.
Click to reveal answer
beginner
What is the role of the association table in many-to-many relationships?
It acts like a bridge connecting two tables by storing pairs of foreign keys. It does not usually have its own data but helps link records.
Click to reveal answer
intermediate
In Flask-SQLAlchemy, which argument is used to define a many-to-many relationship in a model?
The 'secondary' argument in the relationship() function points to the association table that links the two models.
Click to reveal answer
beginner
Why is it important to use many-to-many relationships instead of duplicating data?
It keeps data organized and avoids repetition. This makes the database easier to maintain and faster to query.
Click to reveal answer
In Flask-SQLAlchemy, what does the 'secondary' parameter in relationship() specify?
AThe association table linking two models
BThe primary key of the model
CThe foreign key of the model
DThe name of the database
What does an association table usually contain?
AOnly primary keys
BUser login information
CForeign keys from both related tables
DApplication settings
Which of these is a real-life example of a many-to-many relationship?
AStudents and courses
BEmployee and employee ID
CCountry and capital city
DBook and ISBN number
Why avoid duplicating data when modeling many-to-many relationships?
ATo confuse users
BTo make the database bigger
CTo slow down queries
DTo keep data consistent and easier to update
In Flask-SQLAlchemy, how do you define the association table?
AUsing a function
BUsing db.Table with foreign keys
CUsing a class with no columns
DUsing a string
Explain how to set up a many-to-many relationship in Flask-SQLAlchemy with an example.
Think about how two tables connect through a third table.
You got /4 concepts.
    Why is using an association table better than duplicating data for many-to-many relationships?
    Consider the problems caused by repeating the same data many times.
    You got /4 concepts.