ManyToMany in a Person <> Blog Relationship
A Person can be a subscriber of many blogs.
A Blog can have many subscribers.
1 2 3 4 5 6 |
const Person = { isSubscriberOfBlogs: [] } const Blog = { subscribers = [] } |
But since this is an inefficient way to manage usually a proxy table is used with [PersonID], [BlogID], aka the 2 related data models.
ManyToOne and OneToMany in a Person <> Blog Relationship
A Person can be the owner of many Blogs.
A Blog can have one owner Person.
1 2 3 4 5 6 7 8 9 10 11 12 |
const Person = { id: 1 isOwnerOfBlogs: [10, 20] // OneToMany } const BlogA = { id: 10, owner_id: 1 // ManyToOne } const BlogA = { id: 20, owner_id: 1 // ManyToOne } |
In conclusion, ToMany means it’s an array, ToOne means it’s a single value.