The Importance of a Join Table

My Final Project Journey II

Arnie Serrano
2 min readOct 23, 2020

After creating the Deck table, Card table and DeckCard table, whose purpose is joining the Deck and Card models, I had started working on the frontend and trying to create the association between the cards and decks by putting each card into the database.

It took too long for me to figure out how to do that unfortunately. Usually my mind was going to fetching the localhost associated with the deck then adding the cards I wanted into the card attribute in the Deck database. Which is at this point where my mind started getting confused on how it would work the way my coach had helped me plan out everything. Because I had noticed that I didn’t have a card attribute in my Deck table. I knew that I had a join table, but was unsure how the 3 things would be associated when fetching from the frontend.

So, I decided to modify my Deck table to include a card attribute to hold the cards. Low and behold I managed to get it working with the help of my coach. The cards were passed into an array on the front end, then saved in the backend. The proper deck was called on the show page and all the cards showed up. From what is required of my project, it works. But when going over it with my coach in seeing how it was working I noticed how this wouldn’t be a viable option on a large scale website or app.

As it was working, each card is saved in my database with a unique id, every time it’s added. So for example, if I were to add 20 Forest, land cards, as is recommended for any standard Magic deck, each of the same card would be saved as its own instance. So that means 20 of the same card with the same Id from the API I’m pulling would be added to my database with it’s own unique Id. So basically like this:

Id: 1 { card id:1} Id: 2 {card id: 1} Id: 3 {card id: 1}

Now if you can imagine this type of functionality for large scale websites or apps where if millions of people are using the same card in their decks. That means there’s unnecessary copies of each card for each deck.

So at this point of my project, I have a basic working version with no real big consequences since it’s not a large scale website or app and merely demonstrates basic functionality. My next goal after this is said and done is to convert this to use a join table and see if I can take a step closer to how I want it to operate.

--

--