One-to-Many Bidirectional Relationship

Learn how to create a one-to-many relationship.

We'll cover the following

In this lesson we will create a bidirectional one-to-many relationship where a Player can have many Registrations.

Let’s add some real life constraints to the model.

  • The first one being that every Registration object must be associated with a Player object.
  • Secondly, when we delete a Registration object, the associated Player object should not be deleted.

A bidirectional association between Player and Registration means that we can get all the Registration objects if we have a Player object and vice versa, we can get a Player by using the Registration. Compare this to the unidirectional one-to-many relationship, where we could find the Registration objects given a Tournament but we could not find the Tournament from a Registration object.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.