From 13fdbf885076b22af69bb54dfcac2d9edda36b7d Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 14 Jun 2017 14:29:59 +0200 Subject: [PATCH] Fix sorting in repositories when only assigned selected [SCI-1349] --- app/datatables/repository_datatable.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/datatables/repository_datatable.rb b/app/datatables/repository_datatable.rb index 175d9ec54..d6f4ae306 100644 --- a/app/datatables/repository_datatable.rb +++ b/app/datatables/repository_datatable.rb @@ -244,18 +244,14 @@ class RepositoryDatatable < AjaxDatatablesRails::Base # as sq ORDER BY CASE WHEN sq.custom_field_id = #{column_id} THEN 1 ELSE 2 END #{dir}, sq.value #{dir} # LIMIT #{per_page} OFFSET #{offset}") - RepositoryRow.find_by_sql( - "SELECT repository_rows.*, values.value AS value - FROM repository_rows - LEFT OUTER JOIN (SELECT repository_cells.*, + records.joins( + "LEFT OUTER JOIN (SELECT repository_cells.repository_row_id, repository_text_values.data AS value FROM repository_cells INNER JOIN repository_text_values ON repository_text_values.id = repository_cells.value_id WHERE repository_cells.repository_column_id = #{column_id}) AS values - ON values.repository_row_id = repository_rows.id - WHERE repository_rows.repository_id = #{@repository.id} - ORDER BY value #{dir} LIMIT #{per_page} OFFSET #{offset}" - ) + ON values.repository_row_id = repository_rows.id" + ).order("values.value #{dir}") else super(records) end