Class: CustomFieldEnumeration

Inherits:
ActiveRecord::Base
  • Object
show all
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.

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



68
69
70
71
72
# File 'app/models/custom_field_enumeration.rb', line 68

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



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

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
        enumeration.attributes = enumeration_attributes
        unless enumeration.save
          raise ActiveRecord::Rollback
        end
      end
    end
  end
end

Instance Method Details

#custom_valuesObject



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

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

#destroy(reassign_to = nil) ⇒ Object



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

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



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

alias :destroy_without_reassign :destroy

#in_use?Boolean

Returns:

  • (Boolean)


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

def in_use?
  objects_count > 0
end

#objects_countObject



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

def objects_count
  custom_values.count
end

#to_sObject



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

def to_s
  name.to_s
end