Let's assume I have two Rails ActiveRecord models, CarType (make/model of car) and Car (instance of a CarType). Car *belongs_to* CarType, and CarType *has_many* Cars.
I want a list of Cars, but only with unique CarTypes (no duplicate CarTypes in the results).
Basically, I want the results of:
CarType.find(:all, :include => [:cars])
...but cast as a collection of Car objects instead. How can I accomplish this?
EDIT
I started solving this by executing the CarType.find statement above, reverse-engineering Rails' generated SQL code (Rails actually produces two SQL statements) and then using Car.find_by_sql, but I feel the solution becomes very bulky.