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