Hi all,
I am trying to get ActiveRecord to perform the following query:
SELECT A.*, B.*, C.* FROM A INNER JOIN B ON B.ID = B_ID INNER JOIN C ON C.ID = C_ID
The dataset is rather large, and I need as the best performance, hence this specific query.
I have my models and query as follows:
class A < ActiveRecord::Base
belongs_to :b
belongs_to :c
end
A.find :all, :include => [:b, :c], :joins => [:b, :c]
However this results in the following queries performed:
SELECT A FROM A INNER JOIN B ON B.ID = B_ID INNER JOIN C ON C.ID = C_ID
SELECT * FROM B WHERE ID IN (...)
SELECT * FROM C WHERE ID IN (...)
Is there any way to make ActiveRecord cleverer and not do the second two queries?
Regards,
Luca Spiller