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 inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#cached_observation_matrix_column_item_idInteger

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 scope: [:observation_matrix_id, :project_id]

  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

#descriptor_idInteger

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 scope: [:observation_matrix_id, :project_id]

  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

#observation_matrix_idInteger

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 scope: [:observation_matrix_id, :project_id]

  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

#reference_countInteger

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 scope: [:observation_matrix_id, :project_id]

  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

.sort(array) ⇒ Object

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

#set_reference_countObject (protected)



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

def set_reference_count
  reference_count ||= 0
end