select 高速化のヒント
class Parent has_many :childs end class Child belongs_to :parent end
has_many の配列データ側を絞り込む。なければ parent も返らない。
Parent.includes(:childs).where("childs.age > ?", 20).references(:childs)
belongs_to のデータを事前にロードし、自身を絞り込む
Child.includes(:parent).where(name: "child name")
belongs_to のデータを事前にロードし、自身を絞り込む
Child.includes(:parent).where("parent.name = ?", "parent name")