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?
✗ Incorrect
The 'secondary' parameter tells SQLAlchemy which table acts as the bridge for the many-to-many relationship.
What does an association table usually contain?
✗ Incorrect
An association table stores foreign keys from the two tables it connects to represent the many-to-many links.
Which of these is a real-life example of a many-to-many relationship?
✗ Incorrect
Students can enroll in many courses, and courses can have many students, making it many-to-many.
Why avoid duplicating data when modeling many-to-many relationships?
✗ Incorrect
Avoiding duplication keeps data clean, consistent, and easier to maintain.
In Flask-SQLAlchemy, how do you define the association table?
✗ Incorrect
The association table is defined with db.Table and includes foreign keys to the related tables.
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.