My head is spinning a bit this morning - can somebody help me with this?
Given these two models with the following associations:
class Article < ActiveRecord::Base
- has an attribute called “published_on”
class Category < ActiveRecord::Base
I need to list all categories, the order should be determined by the
“published_on” date of their latest associated article.
So for example:
cat1 = Category.create
cat1.articles.create(:published_on => 5.days.ago)
cat1.articles.create(:published_on => 4.days.ago)
cat2 = Category.create
cat2.articles.create(:published_on => 2.days.ago)
Then my list should be ordered:
I believe this would be trivial to make in raw SQL, but I have trouble
figuring out, how to do it with AR’s find() method.