ruby on rails - Meta_search error with model associations -
i have these in controller:
class accountscontroller < applicationcontroller def index @search = account.search(params[:search]) @accounts = @search.order("id desc").includes(:chef).page(params[:pagina]).per(10) end end my view:
<%= f.text_field :username_or_email_or_chef_name_contains %> works fine! but, when search based on email, got error:
activerecord::statementinvalid in accounts#index mysql2::error: column 'id' in order clause ambiguous: select `accounts`.`id` t0_r0, `accounts`.`chef_id` t0_r1,... if take off .includes(:chef) of account controller, works fine.
question
why error? performance reasons, wouldn't remove include account controller.
the accounts table , chefs table each have id column, mysql doesn't know of columns should order by. try specifying table name in order clause:
@accounts = @search.order("accounts.id desc").includes(:chef).page(params[:pagina]).per(10)
Comments
Post a Comment