@@ -139,8 +139,9 class CustomField < ActiveRecord::Base | |||
|
139 | 139 | case field_format |
|
140 | 140 | when 'string', 'text', 'list', 'date', 'bool' |
|
141 | 141 | # COALESCE is here to make sure that blank and NULL values are sorted equally |
|
142 | self.custom_values.first.to_sql | |
|
142 | 143 | "COALESCE((SELECT cv_sort.value FROM #{CustomValue.table_name} cv_sort" + |
|
143 | " WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" + | |
|
144 | " WHERE cv_sort.customized_type='#{self.class.customized_class.base_class.name}'" + | |
|
144 | 145 | " AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" + |
|
145 | 146 | " AND cv_sort.custom_field_id=#{id} LIMIT 1), '')" |
|
146 | 147 | when 'int', 'float' |
@@ -148,7 +149,7 class CustomField < ActiveRecord::Base | |||
|
148 | 149 | # Postgresql will raise an error if a value can not be casted! |
|
149 | 150 | # CustomValue validations should ensure that it doesn't occur |
|
150 | 151 | "(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.table_name} cv_sort" + |
|
151 | " WHERE cv_sort.customized_type='#{self.class.customized_class.name}'" + | |
|
152 | " WHERE cv_sort.customized_type='#{self.class.customized_class.base_class.name}'" + | |
|
152 | 153 | " AND cv_sort.customized_id=#{self.class.customized_class.table_name}.id" + |
|
153 | 154 | " AND cv_sort.custom_field_id=#{id} AND cv_sort.value <> '' AND cv_sort.value IS NOT NULL LIMIT 1)" |
|
154 | 155 | else |
General Comments 0
You need to be logged in to leave comments.
Login now