Define Relationships and Foreign Keys
Link models with one-to-many associations.
Rows That Belong Together
Real data connects: a user has many posts, an order has many items. A relationship links these rows in your models. 🔗
The Foreign Key
A foreign key is a column on the child that stores the parent's id. It is the actual link saved in the database.
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))All lessons in this course
- Fetch Rows with query and get
- Filter, Order, and Limit Results
- Define Relationships and Foreign Keys
- Joins and Lazy vs Eager Loading