19 August ActiveRecord :joins

Wednesday, August 19th, 2009 - 12:20 pm

I didn’t know that the :joins option for ActiveRecord accepted named associations. This works perfectly when you want to join with a table to retrieve information without actually “including” the model. It also makes the query much simpler.

Just be sure to always use :select when using :joins, or joined tables may overwrite attributes primary table in the result (i.e. the id attribute).

Comments are closed.