Why do we need a through table explained with Rails?by@fer
367 reads

Why do we need a through table explained with Rails?

October 20th 2020
6 min
by @fer 367 reads
tldt arrow
Read on Terminal Reader🖨️

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

@fer

Fernando Rivas
react to story with heart

RELATED STORIES

L O A D I N G
. . . comments & more!
Hackernoon hq - po box 2206, edwards, colorado 81632, usa