2012-06-04 2 views
0

내 컨트롤러이 있습니다Meta_search 오류

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 %> 

작품 벌금을! 잘 작동 계정 컨트롤러의 : (요리사) 나는 .includes을 가지고가는 경우에

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,... 

: 나는 이메일에 따라 를 검색 할 때, 나는이 오류가 발생했습니다.

질문

왜이 오류? 성능상의 이유로 계정 컨트롤러에서 include을 삭제하고 싶지 않습니다.

답변

1

accounts 테이블과 chefs 테이블에는 각각 id 열이 있으므로 MySQL은 주문해야하는 열을 알지 못합니다. order by 절에서 테이블 이름을 지정하십시오.

@accounts = @search.order("accounts.id desc").includes(:chef).page(params[:pagina]).per(10) 
+0

감사합니다! 알았다. – maiconsanson