The rest of the day we delved into Active Record which was actually a lot of fun, where we learned about object-relational mapping. We played around with making queries and setting up new databases. Setting up Active Record does involve a number of steps that are somewhat confusing like putting together the models and database connections. In general it was pretty interesting seeing how to set up database schemas and seeding the databases.
We used AR to perform CRUD actions that include create, new, save, all, find, find_by, where, update, and destroy. I learned about how to connect to the database with postresql in order to actually get the queries to work. And the instructors discussed how convention is more important than configuration, and the conventions are a bit odd, it will take some time to get used to which ones are singular, plural, snake case, and camel case. Here’s an overview of the conventions covered:
- Model file names are singular and snake case
- Model class names are singular and camel case
- Database schema is plural
Overview of the methods covered:
- Class methods include all, new, first, last, and find
- Instance methods include attr_accessors, destroy, save, and update