##// END OF EJS Templates
Fixed that grouping issue by key/value custom field does not work (#22178)....
Jean-Philippe Lang -
r14842:e0ae0f287a5f
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,74 +1,80
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class CustomFieldEnumeration < ActiveRecord::Base
19 19 belongs_to :custom_field
20 20 attr_accessible :name, :active, :position
21 21
22 22 validates_presence_of :name, :position, :custom_field_id
23 23 validates_length_of :name, :maximum => 60
24 24 validates_numericality_of :position, :only_integer => true
25 25 before_create :set_position
26 26
27 27 scope :active, lambda { where(:active => true) }
28 28
29 29 def to_s
30 30 name.to_s
31 31 end
32 32
33 33 def objects_count
34 34 custom_values.count
35 35 end
36 36
37 37 def in_use?
38 38 objects_count > 0
39 39 end
40 40
41 41 alias :destroy_without_reassign :destroy
42 42 def destroy(reassign_to=nil)
43 43 if reassign_to
44 44 custom_values.update_all(:value => reassign_to.id.to_s)
45 45 end
46 46 destroy_without_reassign
47 47 end
48 48
49 49 def custom_values
50 50 custom_field.custom_values.where(:value => id.to_s)
51 51 end
52 52
53 53 def self.update_each(custom_field, attributes)
54 54 return unless attributes.is_a?(Hash)
55 55 transaction do
56 56 attributes.each do |enumeration_id, enumeration_attributes|
57 57 enumeration = custom_field.enumerations.find_by_id(enumeration_id)
58 58 if enumeration
59 59 enumeration.attributes = enumeration_attributes
60 60 unless enumeration.save
61 61 raise ActiveRecord::Rollback
62 62 end
63 63 end
64 64 end
65 65 end
66 66 end
67 67
68 def self.fields_for_order_statement(table=nil)
69 table ||= table_name
70 columns = ['position']
71 columns.uniq.map {|field| "#{table}.#{field}"}
72 end
73
68 74 private
69 75
70 76 def set_position
71 77 max = self.class.where(:custom_field_id => custom_field_id).maximum(:position) || 0
72 78 self.position = max + 1
73 79 end
74 80 end
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now