The One-to-One Relationship
Understand how to establish a one-to-one relationship between Employee and Department models in Flask using SQLAlchemy. Learn to add ForeignKey columns, use relationship with backref, and set useList to False to ensure a single association.
Introduction #
In the last lesson, we created a one-to-many relationship between the Employee and Department models. The code so far is given below:
Now, let’s learn how to add a one-to-one relationship between these models as well.
Representing a one-to-one relationship in models
In this example, a one-to-one relationship should exist between the Employee and Department. This relationship will indicate that an employee can be the head of a ...