custom_field.rb.patch

Devadatta Sahoo, 2012-06-01 20:06

Download (1.64 KB)

View differences:

app/models/custom_field.rb
121 121
  # objects by their value of the custom field.
122 122
  # Returns false, if the custom field can not be used for sorting.
123 123
  def order_statement
124
    customized_type_classname = (self.class.customized_class.name == 'User') ? self.class.customized_class.superclass.name : self.class.customized_class.name
124 125
    case field_format
125 126
      when 'string', 'text', 'list', 'date', 'bool'
126 127
        # COALESCE is here to make sure that blank and NULL values are sorted equally
127 128
        "COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" +
128
          " WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
129
          " WHERE cv_sort.customized_type='#{customized_type_classname}'" +
129 130
          " AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
130 131
          " AND cv_sort.custom_field_id=#{id} LIMIT 1), '')"
131 132
      when 'int', 'float'
......
133 134
        # Postgresql will raise an error if a value can not be casted!
134 135
        # CustomValue validations should ensure that it doesn't occur
135 136
        "(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort" +
136
          " WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" +
137
          " WHERE cv_sort.customized_type='#{customized_type_classname}'" +
137 138
          " AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" +
138 139
          " AND cv_sort.custom_field_id=#{id} AND cv_sort.value <> '' AND cv_sort.value IS NOT NULL LIMIT 1)"
139 140
      else