Creating Relationships
After my first few weeks at coding boot camp. One topic I felt that has been really important with Ruby and Object-Oriented programming, in general, is being able to recognize and map out relationships between classes and tables. We have learned about different types of relationships throughout the course so far and how to create relationships.
Some problems definitely require more thought than others to map out the relationships, and some are straightforward and make it pretty clear within the problem or lab. We have done a lot of work focusing on many to many relationships and I have learned how to spot and map these relationships. A good example of this is for a rideshare app three classes are passenger, driver, and ride. The many to many here would be the driver and the passenger, as a driver has many passengers and a passenger has many drivers. But, for one ride a driver is connected to one passenger and a passenger is connected to one driver, so ride is the join table connecting this many to many relationship.
Working through labs I was able to spot these relationships and with my labs and problems, I was able to draw out these relationships. Most labs were set out with all the classes we needed to create(and most only used 3 classes). However, when I came to a problem with a movie database and creating models for relationships. The problem set out four classes Movie, Show, Character, and Actor and described the relationships as so:
So, without thinking about it too much I tried creating these 4 classes shown above and tried to achieve the deliverables and create relationships between the tables. From what looks obvious to me now I wasn’t able to get very far in this problem. Fortunately, with the program, I am in I was able to work with another person in my class and ask our teachers for help who made me realize I was looking at the problem wrong and that all the classes or tables aren’t going to be laid out for you. You really have to think about the problem map it out and see if it makes sense. In my model above I had two many to many relationships without join tables, the problem didn’t explicitly spell it out, that we needed extra tables in there. But, it was up to me to pick up on this and create these tables. With the join tables, this is how my model looked and was able to function as I needed it to.
Overall working through this problem I can see without the appropriate relationships set out we will be unable to complete it as we need to. Furthermore, when working and creating our own projects and relationships we aren’t confined to a set number of classes or relationships we can use, we have to consider the problem or the program we are trying to create and use what is right for that problem.