Ruby rails - select only few columns from the data base

前端 未结 6 1510
[愿得一人]
[愿得一人] 2020-12-15 02:16

What is the way in rails to structure sql query to only select certain columns from the database, I have some large data fields which I want to avoid loading from continuous

6条回答
  •  一向
    一向 (楼主)
    2020-12-15 03:04

    Using Arel (aka in Rails 3), use:

    Item.where(...).select("name, address")
    

    Also, it seems .select gets ignored if you tack on a scope that has an :include => ...

提交回复
热议问题