Class: CustomFieldEnumeration
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CustomFieldEnumeration
show all
- Includes:
- Redmine::SafeAttributes
- Defined in:
- app/models/custom_field_enumeration.rb
Overview
Redmine - project management software Copyright (C) 2006-2016
Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Class Method Summary
collapse
Instance Method Summary
collapse
#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=
Class Method Details
.fields_for_order_statement(table = nil) ⇒ Object
78
79
80
81
82
|
# File 'app/models/custom_field_enumeration.rb', line 78
def self.fields_for_order_statement(table=nil)
table ||= table_name
columns = ['position']
columns.uniq.map {|field| "#{table}.#{field}"}
end
|
.update_each(custom_field, attributes) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/custom_field_enumeration.rb', line 59
def self.update_each(custom_field, attributes)
return unless attributes.is_a?(Hash)
transaction do
attributes.each do |enumeration_id, enumeration_attributes|
enumeration = custom_field.enumerations.find_by_id(enumeration_id)
if enumeration
if block_given?
yield enumeration, enumeration_attributes
else
enumeration.attributes = enumeration_attributes
end
unless enumeration.save
raise ActiveRecord::Rollback
end
end
end
end
end
|
Instance Method Details
#custom_values ⇒ Object
55
56
57
|
# File 'app/models/custom_field_enumeration.rb', line 55
def custom_values
custom_field.custom_values.where(:value => id.to_s)
end
|
#destroy(reassign_to = nil) ⇒ Object
48
49
50
51
52
53
|
# File 'app/models/custom_field_enumeration.rb', line 48
def destroy(reassign_to=nil)
if reassign_to
custom_values.update_all(:value => reassign_to.id.to_s)
end
destroy_without_reassign
end
|
#destroy_without_reassign ⇒ Object
47
|
# File 'app/models/custom_field_enumeration.rb', line 47
alias :destroy_without_reassign :destroy
|
#in_use? ⇒ Boolean
43
44
45
|
# File 'app/models/custom_field_enumeration.rb', line 43
def in_use?
objects_count > 0
end
|
#objects_count ⇒ Object
39
40
41
|
# File 'app/models/custom_field_enumeration.rb', line 39
def objects_count
custom_values.count
end
|
#to_s ⇒ Object
35
36
37
|
# File 'app/models/custom_field_enumeration.rb', line 35
def to_s
name.to_s
end
|