Preloading associations while using find_by_sql

To preload the associated records we generally use #includes, #preload or #eager_load for more information please see this blog This will work perfectly if we preload associations for an ActiveRecord::Relation, but in case if we want to load associated records for an Array, these methods will fail Let's consider this example class Company < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :company end Say we have a query, which is performing joins and also have sub queries, then we would need to use find_by_sql, to generate the query. But find_