Rails ransacks 关联搜索排序报错

zhg · April 20, 2017 · Last by 5swords replied at April 21, 2017 · 1270 hits

我现在使用 ransacks 来进行搜索操作

@q = Order.ransack(params[:q].merge(shipping_print_status_eq: Shipping::PrintStatus::PRINTING))

@orders = @q.result(distinct: true)

@orders = @orders.includes(:shipping).order("shippings.print_at DESC NULLS LAST")

error

ActiveRecord::StatementInvalid - PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list

请问不使用 .to_a.uniq 这种方法怎么来解决

Order distinct 有用吗?

zhg closed this topic. 26 Apr 10:27
You need to Sign in before reply, if you don't have an account, please Sign up first.