Skip to content

bug when sorting by association when using postresql with distinct(:true) #429

@gotqn

Description

@gotqn

I know this is a known bug:

  1. http://stackoverflow.com/questions/19748959/ransack-postgres-sort-on-column-from-associated-table-with-distinct-true
  2. http://stackoverflow.com/questions/19910574/distinct-for-sorting-with-ransack

but is there a fix?

This code works:

def index
  @search = LogFile.search(params[:q])
  @log_files = @search.result(distinct: false).includes(:search_statistic).page(params[:page]).per(5)
end

This code does not:

def index
  @search = LogFile.search(params[:q])
  @log_files = @search.result(distinct: true).includes(:search_statistic).page(params[:page]).per(5)
end

Error:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions