Reflecting on Active Record Associations
summary
Builds working replacements for belongs_to/has_many macros that dynamically define reader and writer methods and shows how a Reflection class derives class, primary key, and foreign key. Implements an Association class that caches targets so repeated loads return the same object, a CollectionProxy subclass that delegates loading and create to the association, and an inverse lookup that prevents N+1 queries by reusing the owner. Source files named include reflection.rb and the Association and CollectionProxy implementations.
AI-written summary · about
chapters (9)
- 0:00Start
- 4:23Study Guide
- 5:09Metaprogramming
- 9:56Reflections
- 12:21Caching
- 16:55Relations
- 24:48Inverses
- 29:35Further Studies
- 30:47Practical Applications
related talks
34mRefactoring Rails
27mRediscovering ActiveRecord
42mActiveRecord is Still Magical
29mActiveRecord, the Repository Pattern, and You
21mActiveRecord can't do it? Arel can!
19mAn ActiveRecord Rewrite: the Story Behind the Attributes API
41mAn Intervention for ActiveRecord
35mAdvanced aRel: When ActiveRecord Just Isn't Enough
