This:
Foo.find(:all, :select => "foos.id, foos.title, (select count(*) from bars where bars.foo_id = foos.id) as count")
performs a select such as this:
SELECT foos.id, foos.title, (select count(*) from bars where bars.foo_id = foos.id) as count FROM foos
But this:
Foo.with_scope(:find => {:include => :bar}) do
Foo.find(:all, :select => "foos.id, foos.title, (select count(*) from bars where bars.foo_id = foos.id) as count")
end
produces:
SELECT foos."id" AS t0_r0, foos."created_at" AS t0_r1, foos."updated_at" AS t0_r2 FROM foos LEFT OUTER JOIN bars ON bars.id = foos.bar_id
In other words, the :include overrides the :select, even though you would expect the opposite to happen.