Class: CustomFieldEnumeration

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/custom_field_enumeration.rb

Overview

Redmine - project management software Copyright (C) 2006-2017 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.

Since:

  • 3.2.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fields_for_order_statement(table = nil) ⇒ Object

Since:

  • 3.2.1



70
71
72
73
74
# File 'app/models/custom_field_enumeration.rb', line 70

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/custom_field_enumeration.rb', line 52

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_valuesObject



48
49
50
# File 'app/models/custom_field_enumeration.rb', line 48

def custom_values
  custom_field.custom_values.where(:value => id.to_s)
end

#destroy(reassign_to = nil) ⇒ Object



41
42
43
44
45
46
# File 'app/models/custom_field_enumeration.rb', line 41

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_reassignObject



40
# File 'app/models/custom_field_enumeration.rb', line 40

alias :destroy_without_reassign :destroy

#in_use?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/custom_field_enumeration.rb', line 36

def in_use?
  objects_count > 0
end

#objects_countObject



32
33
34
# File 'app/models/custom_field_enumeration.rb', line 32

def objects_count
  custom_values.count
end

#to_sObject



28
29
30
# File 'app/models/custom_field_enumeration.rb', line 28

def to_s
  name.to_s
end