ActiveRecord is a type of Object Relational Mapper (ORM) in the form of a Ruby gem. It is used by programmers to ease the pain of managing SQL databases and allows for the (relatively simple) creation of relationships between models. The best part? ActiveRecord syntax looks pretty close to ‘plain English’–i.e., much more intuitive than writing and deciphering complex SQL queries.

Though there are several types of associations you can use in ActiveRecord, I’ll be covering the ones you’ll encounter the most as you begin using this tool. I’ve created some simple graphics in order to better understand these relationships.
The simplest relationship is the one-to-one relationship, belongs_to, which indicates that each instance of one model (e.g., painting) belongs to a single instance of another (e.g., artist).

We could also think of an artist as having many paintings. This relationship is an example of a has_many relationship, but this time with Artist being the declaring class.

Another association to consider is has_many through:. This time, we’re working with art collectors. In this type of relationship, Painting would be considered a ‘join class’, because the collector wouldn’t have anything to collect if the artist didn’t create any paintings! The painting class must exist to create an association between the artist and collector. Therefore, the collector ‘has’ many associated artists through the paintings they collect.

If you’d like to read more about AR associations and/or see relevant examples of Ruby code, take a look at the Rails Guide on AR Basics.
