The Lapidary Lemur

Musings from Brandon Weaver

Association Aggregates Explained

The last post covered some of the basics of aggregate commands, but left out a section explaining the more perilous aggregates of associations and more advanced querying against them.

Here are a few questions to get you thinking before we start. Given a model Foo which has_many Tags (key, value, foo_id):

  • How do we find the count of tags for every Foo?
  • How do we find a Foo with multiple matching tags? (name: ‘David Tennant’ AND color: ‘Blue’)

Suddenly ActiveRecord becomes very annoyingly complicated to use, but not to fear! We can still use SQL for all of this.

Aggregate Active Record

Active Record is an extremely powerful abstraction on SQL, but many a Rails programmer tends to forget that that means the entirety of the SQL standard. While it might be common knowledge for some, aggregate queries seem to be missing from the toolkit of a newer rails programmer.

The Clairvoyant Project

The Clairvoyant project is one of my more ambitious personal projects, with one “simple” goal in mind: Your tests should be able to generate your application code

This post will outline the beginnings of the madness that led to Clairvoyant as well as some of the details of how things are planned to be implemented.