典型场景:
SomeModule.find(:all, :conditions ["xyz" = ?, some_var]
SomeModule.find(:first, :conditions ["xyz" = ?, some_var]
SomeModule.find(:last, :conditions ["xyz" = ?, some_var]
期望的等价物:
虽然上面三个例子都很棒,但我正在寻找“仅”请求特定列的正确方法,例如:
SomeModule.find(:first_name, last_name, city :conditions ["xyz" = ?, some_var]
-- 或者也许--
SomeModule.find(:only => :first_name, :last_name, :city :conditions ["xyz" = ?, some_var]
消除查询中不必要列的 Rails 方法是什么?
最佳答案
SomeModule.find(:select => "first_name, last_name, city" ... )
关于mysql - 如何只查询特定的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9168916/