Relational Database (Joris) - pmvdbijl7/matching-app GitHub Wiki

Relational Database

What is it?

A relational database is a database that has items which have relations with other items using their unique ID.

Relationship types and examples why you could use them

One-To-One (1:1)

This means 1 item from a certain table/collection only has a relation with 1 item from another table/collection and that item only has 1 relation with the other item.

Example:

A class only has one SLB coach and that SLB coach only guides one class.

One-To-One relationship example

One-To-Many (1:N)

This means 1 item from a certain table/collection can have a relation with multiple items from another table/collection and those items only have 1 relation with the other item.

Example:

A social media site has users, a user can write multiple messages, but each message is only be written by that one user.

One-To-Many relationship example

Many-To-Many (N:N)

This means multiple items from a certain table/collection can have a relation with multiple items from another table/collection and vice versa. In a Relational Database a Many-To-Many relation needs an association table (also known as join or junction table) because an attribute of an entity can only have one value assigned, but because MongoDB is document based it can save multiple ID's of other items in an array or object.

Example:

A subject is given to multiple students and a student follows multiple subjects.

One-To-One relationship example

Examples within our project

User 'Liking' other users' profiles

When a user is visiting someone else's profile they can 'Like' that person by clicking a button. When pressed it sends the ID of the current profile being visited to the server and this ID is placed in the liked_profiles array. Now this user item has a relation with the user item that has been liked, because a user can like multiple users and vice versa so this is a many-to-many relationship (N:N).

User having favorite genres

When a user creates a new account or edits their profile they can select their favorite movie/serie genre from a list. The items in this list are loaded from a database collection called genres. When the user selects their favorite genres and submits the data to the database the ID's of the selected genres are saved in the genres array of a user item similar to the liked_profiles. This is also a many-to-many relationship (N:N), because a user can have multiple favorite genres and a genre can be favorited by multiple users.

Resources: