我知道我可以使用pluck
指定某些字段来查询数据库。
ids = Item.where('due_at < ?', 2.days.from_now).pluck(:id)
但是我想知道,是否有办法指定某些字段我想避免从db中查询。某种反拔?
posts = Post.where(published: true).do_not_lookup(:enormous_field)
答案 0 :(得分:7)
Model#attribute_names
应返回列/属性数组。您可以排除部分内容并转到pluck
或select
方法。
这样的事情:
posts = Post.where(published: true).select(Post.attribute_names - ['enormous_field'])