Posted almost 5 years ago. Visible to the public.

Migrations [2d]



In MovieDB, add two fields:

: This field should cache the total number of movies an actor stars in

: This field should cache the first movie to which the actor was ever assigned in MovieDB

Add callbacks to your ActiveRecord models so the field is always up to date. For the purpose of this exercise, please don't use the :counter_cache option and do everything manually instead.

Whenever you add a new column you need to take care of existing records. Add a migration that sets the total_movies and first_movie_id column for existing records. Write this migration in multiple styles:

  • Embedding ActiveRecord models into your migration
  • SQL statements (update "UPDATE actors SET ...")
  • Helper methods from the database adapter

Owner of this card:

Henning Koch
Last edit:
9 months ago
by Hannes Randow
rails, activerecord
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more