For further actions, you may consider blocking this person and/or reporting abuse
Read next

Revealed: How Language AI Skills Actually Grow - New Study Groups Tasks to Predict Improvements
Mike Young -

Kitsune: New GPU System Speeds Up Machine Learning 2.4x Using Smart Data Flow Management
Mike Young -

Hard links in Linux
pikoTutorial -

AI Model Evaluation Breakthrough: New System Automates Performance Testing with 89% Accuracy
Mike Young -
Top comments (2)
One to many: For example a blog post and comments.
Every blog post can have many comments but each comment only belongs to one blog post.
The way this is implemented is by giving every comment a
blog_post_id
so you can query the database for every comment with ablog_post_id
that equal's the blog post'sid
.Many to many: For example tags on a blog post.
Every blog post can have many tags (this one, for example, has two; #orm and #explainlikeimfive), and every tag can be attached to many blog posts (searching #explainlikeimfive will bring up many posts).
This cannot be implemented by adding a
blog_post_id
attribute to tags, because every tag needs to be able to have manyblog_post_id
s, instead, it's implemented using a join table.A join table is a table that has two columns,
blog_post_id
andtag_id
. Every time you want to add a tag to a blog post you add an entry to the join table with the id of the blog post and the id of the tag. Getting a list of all the tags that were applied to a given article is done by querying the join table for all of thetag_id
s where theblog_post_id
matches your blog post and vice versa for getting a list of all of the articles with a given tag.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 andtag.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 theBLOG_POST
andTAG
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.