find_by_sql Blogs
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
Kiprosh is now part of LawLytics
Written by Kiprosh, team of passionate and disciplined craftsmen turning your ideas into reality.
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_