redmine: How can I sort by custom field in module

402 views Asked by At

I`ve got

issue.descendants.visible.sort_by(&:lft)

which gets descendant issues sorted my :lft

How can I sort by custom field with was created via CustomField module?

1

There are 1 answers

1
General Failure On

You can sort issues by custom field values via tables join

issues = Issue.all.joins("left outer join #{CustomValue.table_name} on #{CustomValue.table_name}.customized_type='#{Issue.name}' and #{CustomValue.table_name}.customized_id=#{Issue.table_name}.id")
issues = issues.order "#{CustomValue.table_name}.value"

Just add nessecary conditions in join expression (in this example takes all custom issue values)