Contents
- 1. What is the Active Record Pattern?
- 2. Magento's Adaptation: Model + ResourceModel
- 3. AbstractModel: Data Without DB Logic
- 4. ResourceModel: The Database Layer
- 5. CRUD Operations in Detail
- 6. Events and Before/After Hooks
- 7. Building Your Own Model + ResourceModel
- 8. Repository Pattern as a Modern Alternative
- 9. Direct Model vs. Repository: When to Use What?
- 10. Conclusion: Understanding and Replacing Active Record Properly
When Magento developers write $product->save(), they are using the Active Record Pattern. The model knows itself, its state, and how to persist itself to the database. Martin Fowler described