Lighthouse W3D4 – before DESTROY

Today we learned about ActiveRecord Callbacks. Callbacks are methods that are called at different stages of an object’s ‘life’ or cycle. We implement callbacks in our models whenever a change to one object affects data in an associated object. (There are other scenarios too, like when you want to modify data before it’s saved.)

A real life example would be a company and employees. If the company closes down (company object changes), then all the employees are not employees anymore! This would be an example where we would use before_destroy. Before deleting the company object (and associated company row in the database), you would delete all the employees too.
There’s an even better way to do this –> has_many :employees, dependent: :destroy. Destroy makes the method sound so epic.

Destroyer from Thor
Destroyer from Thor

We also had the privilege of having Stephen Steneker from MongoDB come in and give a talk on MongoDB database schema design. A lot of it unfortunately went over my head, but it was interesting to see a different approach to storing data (bson versus the tables in relational databases).

Tomorrow is Assessment #2 on ActiveRecord and SQL… it has been a crazy week in that we just started AR late Tuesday and have a test on Friday morning! I feel like I’ve done most of the assignments but am not sure if I have learned it… SQL also feels like weeks ago even though it was last weekend.

Most important skill at Lighthouse Labs: learn to learn really fast.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s