ActiveRecord选择除列 [英] ActiveRecord select except columns

查看:73
本文介绍了ActiveRecord选择除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以指定选择ActiveRecord中的所有列(仅少数列)。例如,对于一个用户,我不想选择其密码哈希或电子邮件。这可能吗,还是我必须手动对所有列进行硬编码?

Is there a way I can specify to select ALL columns in ActiveRecord except just a few. For example, for a User, I don't want to select their password hash or their email. Is this possible or do I have to manually hardcode all columns?

谢谢

推荐答案

编写一个像这样的作用域

write a scope like

def select_without columns
  select(column_names - columns.map(&:to_s))
end

这篇关于ActiveRecord选择除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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