DEV Community

Discussion on: Explain ORM oneToMany, manyToMany relation like I'm five

Collapse
 
nestedsoftware profile image
Nested Software • Edited

This is a very nice answer! I'd just add that in the 'Object' part of ORM, the usage is usually pretty simple. For example, something like blog_post.tags will get the tags associated with a blog post and tag.blog_posts will get the blog posts associated with a given tag.

Behind the scenes the ORM will use its mapping configuration to retrieve these associations from a relational database. That's where a join table is probably going to be used to represent a many-to-many relationship between two tables, e.g. there would be something like an X_BLOG_POST_TAG table that connects the BLOG_POST and TAG tables. However, in your domain code, you usually won't need to be aware of this, which of course is the whole point behind object-relational mapping.