Week 3 Day 3 – Practice Assessments Lessons and More Rails!
Man, associations are kinda confusing. I haven’t really nailed understanding the relationships just yet, but I’m getting better. There’s a fairly simple strategy on implementing it at first when you don’t quite grasp the relationship between each of the classes and it involves delving into the schema to grab foreign id’s and start from there. It seems like you’d typically start the association with a belongs_to
in the class with the foreign id, and go to the class that the foreign id refers to, and set up the has_many
or has_one
relationship there. I feel like if I follow this convention for now, I’ll be able to intimately understand relationships a lot better. It’s a bit ironic though, that as verbose and English-like Ruby on Rails is, if you try to understand the relationship by interpreting the belongs_to and has_many on English terms, you’ll get confused.
Regardless, my partner and I did fairly well today on the associations exercises. Well enough in fact, that I decided to do the practice assessment that night. Lol…. not exactly as confident afterwards, but here’s the thing, I learned A LOT from just taking the practice assessment. The sheer amount of practice I was able to get from doing the practice assessment helped me with understanding queries a bit more as well as the associations. The associations were also tested a bit differently as well. In the projects, we’ve been testing them through pry, whereas the assessment, associations were tested through the RSpec, which was huge for naming conventions of the associations The specs were also very helpful in mapping the relationships.
Oh! A helpful tip i think would help a lot of people in understanding the relationships is to create a chart of all the different id’s that are within the schema. By doing so, you should be able to map out the base relationships, and once you have those mapped out, it’s fairly easy to map out the has-through relationships.
Last night’s readings and homeworks were difficult. Active Relations… which from what I learned is basically utilizing SQL queries with Ruby code, which is both similar and different to object-relational mapping, or ORM. Active relations also has to do with being able to treat the results of those queries as objects. I’m not too clear just yet, a lot more practice and reading needs to be done, but I’m sure I’ll get it with time!
That’s pretty much it for today, another day of study hall so I’m going to get back on those readings, homeworks and today’s project readings. Talk to everyone tomorrow!