Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails select with includes

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

like image 243
Remon Amin Avatar asked Dec 03 '22 22:12

Remon Amin


1 Answers

You're better of using something like

User.joins(:profile).select("users.*, profiles.field1, profiles.field2").limit(10)
like image 93
Hassan Javeed Avatar answered Dec 29 '22 11:12

Hassan Javeed