Class: ObservationMatrixColumn

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::IsData, Shared::Notes, Shared::Tags
Defined in:
app/models/observation_matrix_column.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (Integer) cached_observation_matrix_column_item_id

Returns if the reference_count is 1, and the presence of this column is here because of reference to a /Single/ ObservationMatrixColumnItem column, then cache the ID of that column

Returns:

  • (Integer)

    if the reference_count is 1, and the presence of this column is here because of reference to a /Single/ ObservationMatrixColumnItem column, then cache the ID of that column



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/observation_matrix_column.rb', line 22

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Tags
  include Shared::Notes

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  has_many :observations, foreign_key: :descriptor_id

  after_initialize :set_reference_count

  acts_as_list

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

- (Integer) descriptor_id

Returns the descriptor in the column

Returns:

  • (Integer)

    the descriptor in the column



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/observation_matrix_column.rb', line 22

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Tags
  include Shared::Notes

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  has_many :observations, foreign_key: :descriptor_id

  after_initialize :set_reference_count

  acts_as_list

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

- (Integer) observation_matrix_id

Returns the observation matrix

Returns:

  • (Integer)

    the observation matrix



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/observation_matrix_column.rb', line 22

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Tags
  include Shared::Notes

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  has_many :observations, foreign_key: :descriptor_id

  after_initialize :set_reference_count

  acts_as_list

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

- (Integer) reference_count

Returns a count of how many times this descriptor is referenced from observation_matrix_column_items. A column can be present via individual reference, or via reference through dynamic column sets.

Returns:

  • (Integer)

    a count of how many times this descriptor is referenced from observation_matrix_column_items. A column can be present via individual reference, or via reference through dynamic column sets.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/observation_matrix_column.rb', line 22

class ObservationMatrixColumn < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::Tags
  include Shared::Notes

  belongs_to :observation_matrix, inverse_of: :observation_matrix_columns
  belongs_to :descriptor, inverse_of: :observation_matrix_columns

  has_many :observations, foreign_key: :descriptor_id

  after_initialize :set_reference_count

  acts_as_list

  validates_presence_of :observation_matrix, :descriptor
  validates_uniqueness_of :descriptor_id, scope: [:observation_matrix_id, :project_id]

  # @param array [Array]
  # @return true
  #   incrementally sort the supplied ids
  def self.sort(array)
    array.each_with_index do |id, index|
      ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
    end
    true
  end

  protected

  def set_reference_count
    reference_count ||= 0
  end

end

Class Method Details

+ (Object) sort(array)

Returns true incrementally sort the supplied ids

Parameters:

  • array (Array)

Returns:

  • true incrementally sort the supplied ids



43
44
45
46
47
48
# File 'app/models/observation_matrix_column.rb', line 43

def self.sort(array)
  array.each_with_index do |id, index|
    ObservationMatrixColumn.where(id: id).update_all(position: index + 1) 
  end
  true
end

Instance Method Details

- (Object) set_reference_count (protected)



52
53
54
# File 'app/models/observation_matrix_column.rb', line 52

def set_reference_count
  reference_count ||= 0
end