Defect #11073 ยป custom_field.rb.patch
| app/models/custom_field.rb | ||
|---|---|---|
|
# objects by their value of the custom field.
|
||
|
# Returns false, if the custom field can not be used for sorting.
|
||
|
def order_statement
|
||
|
customized_type_classname = (self.class.customized_class.name == 'User') ? self.class.customized_class.superclass.name : self.class.customized_class.name
|
||
|
case field_format
|
||
|
when 'string', 'text', 'list', 'date', 'bool'
|
||
|
# COALESCE is here to make sure that blank and NULL values are sorted equally
|
||
|
"COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" +
|
||
|
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||
|
" WHERE cv_sort.customized_type='#{customized_type_classname}'" +
|
||
|
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||
|
" AND cv_sort.custom_field_id=#{id} LIMIT 1), '')"
|
||
|
when 'int', 'float'
|
||
| ... | ... | |
|
# Postgresql will raise an error if a value can not be casted!
|
||
|
# CustomValue validations should ensure that it doesn't occur
|
||
|
"(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort" +
|
||
|
" WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
|
||
|
" WHERE cv_sort.customized_type='#{customized_type_classname}'" +
|
||
|
" AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
|
||
|
" AND cv_sort.custom_field_id=#{id} AND cv_sort.value <> '' AND cv_sort.value IS NOT NULL LIMIT 1)"
|
||
|
else
|
||