gpt4 book ai didi

mysql - 在 rails Controller 中使用名字、姓氏的组合来排序结果

转载 作者:太空宇宙 更新时间:2023-11-03 18:24:56 25 4
gpt4 key购买 nike

我想按名字和姓氏的组合对查询结果进行排序。

用户模型的索引定义为

define_index do
indexes :first_name
indexes :last_name

has first_name, :as => :fname
has last_name, :as => :lname
end

在我的 Controller 的操作中,我正在检索这样的结果。

 @results = User.search(query,
:with => options,
:order => "fname ASC",
:match_mode => :extended).page(params[:page]).per(11)

它按 first_name 排序结果,结果是这样的。

              Micheal Clark
Niel Johnson
Micheal Beaven

但我想按名字和姓氏的组合对结果进行排序。像这样的东西应该归还。

              Micheal Beaven
Micheal Clark
Niel Johnson

最佳答案

改变

has last_name, :as => :fname

has first_name, :as => :fname

以下应该有效

:order => "first_name, last_name", 

关于mysql - 在 rails Controller 中使用名字、姓氏的组合来排序结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12746882/

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