Class: ObservationMatrixColumn
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ObservationMatrixColumn
- Includes:
- Housekeeping, Shared::IsData, Shared::Notes, Shared::Tags
- Defined in:
- app/models/observation_matrix_column.rb
Instance Attribute Summary collapse
-
#cached_observation_matrix_column_item_id ⇒ 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.
-
#descriptor_id ⇒ Integer
The descriptor in the column.
-
#observation_matrix_id ⇒ Integer
The observation matrix.
-
#reference_count ⇒ Integer
A count of how many times this descriptor is referenced from observation_matrix_column_items.
Class Method Summary collapse
-
.sort(array) ⇒ Object
True incrementally sort the supplied ids.
Instance Method Summary collapse
- #set_reference_count ⇒ Object protected
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#cached_observation_matrix_column_item_id ⇒ Integer
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.
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 |
# File 'app/models/observation_matrix_column.rb', line 22 class ObservationMatrixColumn < ApplicationRecord include Housekeeping include Shared::Tags include Shared::Notes include Shared::IsData acts_as_list scope: [:observation_matrix_id, :project_id] 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 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_id ⇒ Integer
Returns 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 |
# File 'app/models/observation_matrix_column.rb', line 22 class ObservationMatrixColumn < ApplicationRecord include Housekeeping include Shared::Tags include Shared::Notes include Shared::IsData acts_as_list scope: [:observation_matrix_id, :project_id] 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 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_id ⇒ Integer
Returns 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 |
# File 'app/models/observation_matrix_column.rb', line 22 class ObservationMatrixColumn < ApplicationRecord include Housekeeping include Shared::Tags include Shared::Notes include Shared::IsData acts_as_list scope: [:observation_matrix_id, :project_id] 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 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_count ⇒ Integer
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.
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 |
# File 'app/models/observation_matrix_column.rb', line 22 class ObservationMatrixColumn < ApplicationRecord include Housekeeping include Shared::Tags include Shared::Notes include Shared::IsData acts_as_list scope: [:observation_matrix_id, :project_id] 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 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.
42 43 44 45 46 47 |
# File 'app/models/observation_matrix_column.rb', line 42 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_count ⇒ Object (protected)
51 52 53 |
# File 'app/models/observation_matrix_column.rb', line 51 def set_reference_count reference_count ||= 0 end |