railsがんばる子

Ruby on Railsがんばる子です。胡蝶蘭のECサイトを運営しています。

has_one throughは、includesで代替可能

has_one throughは、includesで代替可能

has_one :fuga
has_one :hoge, through: :fuga
default_scope -> { includes(:hoge).references(:hoge).where(hoge: {id: xxx} }
has_one :fuga
default_scope -> { includes(fuga: :hoge).references(:hoge).where(hoge: {id: xxx} }