paint-brush
Why do we need a through table explained with Rails?by@fer
539 reads
539 reads

Why do we need a through table explained with Rails?

by Fernando Rivas6mOctober 20th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In a many to many relationship, it's just a table between the entities, but what is the purpose of this table to be between them? In Rails we can create two models and these 2 models can be connected just with a foreign key by Active Record Associations. The user_id is going to be our foreign key, remember that primary keys are unique between models, so in order to reference our User model, we can start saying "A User can have many events but an Event belongs to one single user"

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Why do we need a through table explained with Rails?
Fernando Rivas HackerNoon profile picture
Fernando Rivas

Fernando Rivas

@fer

L O A D I N G
. . . comments & more!

About Author

Fernando Rivas HackerNoon profile picture
Fernando Rivas@fer

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite