我的控制器中有这些:
class AccountsController < ApplicationController
def index
@search = Account.search(params[:search])
@accounts = @search.order("id desc").includes(:chef).page(params[:pagina]).per(10)
end
end
我的观点:
<%= f.text_field :username_or_email_or_chef_name_contains %>
工作正常!但是,当我基于 email搜索时,我收到了这个错误:
ActiveRecord::StatementInvalid in Accounts#index
Mysql2::Error: Column 'id' in order clause is ambiguous: SELECT `accounts`.`id` AS t0_r0, `accounts`.`chef_id` AS t0_r1,...
如果我取消帐户控制器的.includes(:chef) ,则可以正常工作。
问题
为什么会出现这个错误?出于性能原因,我不想include
从帐户控制器中删除。