Skip to content

Instantly share code, notes, and snippets.

@madzhuga
Created February 25, 2014 12:40
Show Gist options
  • Save madzhuga/9208075 to your computer and use it in GitHub Desktop.
Save madzhuga/9208075 to your computer and use it in GitHub Desktop.
search_scope = Delivery.accessible_by(current_ability, :read)
search_scope = search_scope.where(state: :quotation_request).
joins(" inner join (select * from (select *, max(id) over (partition by delivery_id) from quotation_requests)t where t.max = t.id)tt on tt.delivery_id = deliveries.id ").
includes(:quotation_requests).
where(quotation_requests: {status: params[:q][:status_in].select(&:present?) })
search_scope = search_scope.search(params[:q])
search_scope = search_scope.order("quotation_requests.id DESC")
set_collection_ivar(search_scope.paginate(page: params[:page], per_page: 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment