rails select with includes

Remon Amin picture Remon Amin · Aug 2, 2013 · Viewed 13.2k times · Source

I have these code in my rails 3.2 application

User.includes(:profile).limit(10)

which select all fields from profiles table I need a way to select on specific fields from profiles table to decrease db queries I am using postgresql

Answer

Hassan Javeed picture Hassan Javeed · Aug 2, 2013

You're better of using something like

User.joins(:profile).select("users.*, profiles.field1, profiles.field2").limit(10)