On the Shoulders of Giants

The further along I get in Flatiron School’s Software Engineering Bootcamp, the more I am blown away by the world of programming. When our cohort was introduced to Object Relational Mapping (ORM) near the start of Phase 2, I was immediately impressed by the idea of translating classes into database tables, where each instance of the class represents a row in that table. With this knowledge, I began to see classes in an entirely new light — they became more than just the elements that create an object (in Object Oriented Programming), they now represent tables of data, and they bring those tables to life. The genius meta-programming of ActiveRecord allows these tables/classes/objects to interact and bump shoulders with each other within your program. And to take things even further, we were introduced to the Model/View/Controller (MVC) application structure, which completely changed my perspective on programming altogether.

In just a couple of months, Flatiron School has provided my cohort with the knowledge to be able to create a functional web application. Our Phase 2 Project utilizes Sinatra and ActiveRecord, as well as the MVC structure. I decided to take the idea that I had for my CLI Project, but instead, write an application to bring the “Hogwarts Social Network” to the web browser.

Everything is Connected

Preliminary Model Associations Map/Diagram

One of the bigger mental hurdles I had to wrap my head around was creating a “has many” to “has many” relationship between two objects derived from the same model. The idea was to allow a Wizard to add other Wizards as friends, and the association would be reflected from both Wizard profiles (the Wizard who added a friend, and the Wizards who were added as friends). I understood, that when creating this type of association between two different models, you would need a “join table” to assist in their relationship. When applying the same idea to just one model, I realized that it’s basically the same concept — you would still need a “join table,” but you can actually tell ActiveRecord which model to look at for the specified attributes. Here’s where specifying the “class_name” and “foreign_key” comes in handy.

ActiveRecord macro methods to allow Wizards to add each other as friends

Once I finally got the hang of how ActiveRecord is able to bring my objects together, I suddenly had the confidence to add more models to my application, and I could see how they would all connect even before creating the user interface or the controller routes. Wizards can have many Posts and many Comments, Posts belong to a Wizard and can also have many Comments, and Comments belong to both a Wizard and a Post. I then realized that if I wanted to add a “Like” or “Upvote” feature, it would basically have the same structure as the Comments model, except we’d just reference its size, as opposed to a Comment’s content. With all of my associations defined, I finally felt comfortable and ready to build my Controllers and Views.

At this point, my brain was deeply inspired and I found myself in some type of programming flow — I just kept on coding for hours straight! I’ve had some experience using Bootstrap in the past, so developing the User Interface in tandem with the logic of my routes went by rather smoothly, and before I knew it, I had a functioning web application.

SQL Query Optimization

Houses Route using ActiveRecord’s .includes() method for SQL Query Optimization

With this knowledge, I was able to update each of my controllers using the .includes() method, and like magic, my application was performing better than ever.

Model, View, Controller

I’m so grateful to be able to stand on the shoulders of the giants who developed such a scalable and reusable structure. This is knowledge that I will absolutely bring with me in every application I work on moving forward.


Hogwarts Social Network ~ Sinatra Edition

Software Engineer | React | Redux | Ruby | Rails