One of the most challenging things about learning Active Record association methods in ruby is the wide range of possibilities condensed into each lesson. However, Active Record is a powerful tool that can correlate data in our database files through simple code to inform each relationship.
We have often discussed that dry code is good code. It is easy to forget that sometimes we need to learn complicated ways of solving problems to reduce the likelihood of creating bugs and increase the possibility that bugs can be found and corrected when they turn up. When deciding between database options, it is tempting to use methods and frameworks that we are familiar with continuously. We like to be comfortable, and we want to know what we are doing. Maybe this isn't the best strategy.
I have learned to be very comfortable with not knowing everything and opening myself up to possibilities I haven't considered before. Acknowledging a lack of understanding can be a strength in coding and can often lead you in the right direction. When learning React, I had no choice but to accept that a deep understanding of a tool takes a lot of practice and time, we don't have all the time in the world to learn everything there is to know about everything, and that is okay. When moving on to Ruby, I quickly accepted that I was not about to understand every aspect of this language before it was time to move on. I completed my assignments to the best of my ability and got to work studying SQL. SQL was a similar story to Ruby.. that said, it was easier to accept that I would be running through lessons very quickly on my way to Active Record. I studied what made sense to me, learned a lot about what I didn't understand, and was able to use that to realize the benefits of Active Record.
It can be a great benefit in any endeavor to learn enough information to ask the right questions. Knowing what questions to ask makes it much simpler to follow a trail of understanding. It is important to acknowledge where we have blind spots to attempt to understand what and why we may be missing something. I found it incredibly beneficial to practice active learning by carefully studying every code-along lesson I could. I have made it a habit of learning from code-along lessons by pretending that the copy and paste functions are out of bounds. I have learned a lot about clean and structured code through utilizing an imitation approach in every lesson. I don't copy what is in the example. Instead, I rewrite it and understand what I am writing.
I learned the most about Active Record by reviewing examples, solutions, and code-alongs until I understood what was taking place. The reason for this is that Active Record is a convention-based framework. Therefore, it is more important to adhere to the convention than to understand why the convention exists.
An example of this is the naming conventions established when creating a migration.
Model Class - Singular with the first letter of each word capitalized (e.g., BookClub).
Database Table - Plural with underscores separating words (e.g., book_clubs).
Model / ClassTable
Article -> articles
LineItem -> line_items
Deer -> deers
Mouse -> mice
Person -> people
credit: [(https://edgeguides.rubyonrails.org/active_record_basics.html#naming-conventions)]
As you can see above, it is not simply a requirement that we follow specific methods to utilize Active Record. Instead, we simply cannot write to Active Record without adhering to the conventions; otherwise, the properties under the hood will not reciprocate predictably.
Convention-based programming tools are a benefit to the student programmer. They help to limit the scope of what a solution could be and force us to learn how the program wants us to interact with it. By understanding that we don't need to understand every aspect of something to use it effectively, conventional methods become a great help.
Top comments (0)