Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby rails - select only few columns from the data base

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 periodic ajax calls. Reading unnecessarily is resource consuming and slow.

@itemlist = Item.find(:all, :conditions => { .... } ) #this select all columns  

I am looking for SELECT name, address FROM users; instead of SELECT * FROM users;

like image 387
Majoris Avatar asked Apr 21 '12 05:04

Majoris


1 Answers

Rails 3:

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

like image 90
nyaa Avatar answered Sep 28 '22 02:09

nyaa