August 11, 2015 Log No. 328

ORM = Online Relationship Manager

Right? Or is it object-relational mapping? I forget. But that’s what we spent the day doing! It was actually pretty fun, albeit straightforward (not a bad thing!), to wrap our SQL queries/result sets in Ruby objects. Yes, there was a lot of redundant code and setting up 1 to 2 line methods that just looked things up on so-and-so table probably would get pretty tedious by the 3rd or 4th project, but as a first-time experience, think was a great intro to an ORM.

And no Julie Andrews! Phew!

Ruby has some handy methods that allowed us to write some pretty meta code too (or as meta as it’s gotten thus far). Object#instance_variables and Object#instance_variable_get let us write a very general #save function in a parent class that would, upon being called in its children table object classes (Question, Reply, User, etc), fill in the table name, pass the relevant instance variables, and insert or update the table as needed. So instead of having the #save function duplicated in each class with the specifics filled in, we just had one very flexible inherited method. Was pretty satisfying getting that working.

But all this, I realize, is very basic level. Tomorrow we start ActiveRecord, which, based on the readings, seems much more built out.


Leave a Reply

Your email address will not be published. Required fields are marked *

*