Ruby rails - select only few columns from the data base

前端 未结 6 1512
[愿得一人]
[愿得一人] 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 02:59

    Make use of :select construct. Try this:

    @itemlist = Item.select('name, address', conditions: { .... } )
    

    For previous version of Rails:

    @itemlist = Item.find(:all,:select => 'name, address', :conditions => { .... } )
    

提交回复
热议问题