Advanced Active Record

By Tom Copeland. 99 pages. Published Dec 2017.

Available now; buy and download here! You can read a sample chapter - the one on scopes - there too.

Table of Contents

Introduction

Migrations

Queries

Scopes

Associations

Code Traces

Odds and ends

Appendix A - Domain Model

Appendix B - Major Version Changes

Helpful links

SQL AntiPatterns slide deck from Bill Karwin has a great overview of the alternatives around tree structures in SQL around slide 75. Lots of other good SQL pointers in there too.

A good writeup of the attributes API from Karol Galanciak. Clear examples.

Good description of dynamic conditions for has_many from Adrian Serafin. Clearly explains the problem and shows a workaround.

Various prefetching/joining concepts from the Scout blog. I like the question/answer style used here to dig into the interactions of these methods.

Using partial unique indexes from iRonin. This is a great data integrity technique if you're on a database that supports it - e.g., PostgreSQL.

Cool stuff you can do with rails has_one from Rob Dawson. A nice writeup, especially on how to look up a single record from a list.