Learn how to define and manage one-to-one, one-to-many, and self-relation relationships between entities in Amplication.
One-to-One
User
entity and a UserProfile
entity. Each user has only one profile, and each profile belongs to only one user.One-to-Many (Many-to-One)
Project
entity and a Task
entity. One project can have many tasks, but each task belongs to only one project.Many-to-Many
Student
entity and a Course
entity. Many students can enroll in many courses, and each course can have many students.Self-Relation
User
entity, you could create a self-relation to represent managers and employees, where each user can have one manager and multiple employees.Navigate to Entity Fields
Add a New Field and Select 'Relation to Entity'
Selecting 'Relation to Entity' data type
Choose the Related Entity
Selecting the related entity
Configure Relationship Details
Project
to Task
:Project
entity’s “Tasks” field, you would select: “One ‘Project’ can be related to many ‘Tasks’”.
Task
entity (e.g., “Project”). On the Task
entity’s “Project” field, the cardinality would be pre-selected as: “One ‘Task’ can be related to one ‘Project’”.
Configuring One-to-Many Relationship Cardinality
Access ERD View
Examine Relationships
ERD View showing relationships between entities