红宝石轨道 - 从数据库中选择只有几列 [英] Ruby rails - select only few columns from the data base

查看:112
本文介绍了红宝石轨道 - 从数据库中选择只有几列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是铁轨的方式来构造SQL查询从数据库中只能选择某些列,我有我想要避免加载由连续周期性Ajax调用一些大的数据字段。阅读是不必要的资源消耗和缓慢的。

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 

我要寻找 SELECT名,来自用户的地址; 而不是 SELECT * FROM用户;

推荐答案

Rails 3的:

Item.select(姓名,地址)。其中,(......)

这篇关于红宝石轨道 - 从数据库中选择只有几列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆