One to many
In the previous lesson, we saw a classic example of a one-to-many relationship: “a user has many purchases”. Every row in the purchases
table has a column user_id
which references a record in the users
table with this id
.
In SQL terminology user_id
is an example of a foreign key – a column that points to another table.
id | user_id | amount | created_at |
11 | 2604 | 14,99 | 2019-01-02 21:00:29.390141 |
12 | 2866 | 4,99 | 2019-01-01 20:05:16.503062 |
This type of association is called one-to-many because each purchase belongs to a single user and...