gpt4 book ai didi

mysql - 如何只查询特定的列?

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:10 26 4
gpt4 key购买 nike

典型场景:

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" ... )

文档:ActiveRecord::QueryMethods

关于mysql - 如何只查询特定的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9168916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com