dynamic has_many association (for lack of a better name)
October 30, 2009
Filed under Rails problem solving
Tags: :has_many, associations, conditions, lazy load, model
Yesterday I had one of those moments in Rails where I knew there must be a really good way to do something, there had to be. But all I could think of was the brute force way.
Technically speaking, I wanted to create collections of child objects on a parent object where the membership of each collection depended on whether the parent and the child shared an attribute in common.
In simpler terms, imagine you have a group blog. Each post in the blog is written by one of several authors. A Post belongs to an Author. (Read More)