Class: CustomFieldEnumeration
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CustomFieldEnumeration
- Defined in:
- app/models/custom_field_enumeration.rb
Overview
Redmine - project management software Copyright © 2006- 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
- #custom_values ⇒ Object
- #destroy(reassign_to = nil) ⇒ Object
- #destroy_without_reassign ⇒ Object
- #in_use? ⇒ Boolean
- #objects_count ⇒ Object
- #to_s ⇒ Object
Methods inherited from ApplicationRecord
Class Method Details
.fields_for_order_statement(table = nil) ⇒ Object
72 73 74 75 76 |
# File 'app/models/custom_field_enumeration.rb', line 72 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/custom_field_enumeration.rb', line 54 def self.update_each(custom_field, attributes) 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
50 51 52 |
# File 'app/models/custom_field_enumeration.rb', line 50 def custom_values custom_field.custom_values.where(:value => id.to_s) end |
#destroy(reassign_to = nil) ⇒ Object
43 44 45 46 47 48 |
# File 'app/models/custom_field_enumeration.rb', line 43 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
42 |
# File 'app/models/custom_field_enumeration.rb', line 42 alias :destroy_without_reassign :destroy |
#in_use? ⇒ Boolean
38 39 40 |
# File 'app/models/custom_field_enumeration.rb', line 38 def in_use? objects_count > 0 end |
#objects_count ⇒ Object
34 35 36 |
# File 'app/models/custom_field_enumeration.rb', line 34 def objects_count custom_values.count end |
#to_s ⇒ Object
30 31 32 |
# File 'app/models/custom_field_enumeration.rb', line 30 def to_s name.to_s end |