scinote-web/app/models/report_element.rb

39 lines
1.4 KiB
Ruby
Raw Normal View History

2019-05-09 17:10:02 +02:00
# frozen_string_literal: true
2017-06-23 15:19:08 +02:00
class ReportElement < ApplicationRecord
enum type_of: Extends::REPORT_ELEMENT_TYPES
2016-02-12 16:52:43 +01:00
# This is only used by certain elements
enum sort_order: {
asc: 0,
desc: 1
}
validates :position, presence: true
validates :report, presence: true
validates :type_of, presence: true
2019-05-09 17:10:02 +02:00
belongs_to :report, inverse_of: :report_elements
2016-02-12 16:52:43 +01:00
# Hierarchical structure representation
2017-03-09 10:51:54 +01:00
has_many :children,
2021-05-27 16:31:41 +02:00
-> { order(:position) },
2017-03-09 10:51:54 +01:00
class_name: 'ReportElement',
foreign_key: 'parent_id',
dependent: :destroy
2017-06-28 15:21:32 +02:00
belongs_to :parent, class_name: 'ReportElement', optional: true
2016-02-12 16:52:43 +01:00
# References to various report entities
2017-06-28 15:21:32 +02:00
belongs_to :project, inverse_of: :report_elements, optional: true
belongs_to :experiment, inverse_of: :report_elements, optional: true
belongs_to :my_module, inverse_of: :report_elements, optional: true
belongs_to :step, inverse_of: :report_elements, optional: true
belongs_to :result, inverse_of: :report_elements, optional: true
belongs_to :checklist, inverse_of: :report_elements, optional: true
belongs_to :asset, inverse_of: :report_elements, optional: true
belongs_to :table, inverse_of: :report_elements, optional: true
2021-06-10 10:59:34 +02:00
belongs_to :repository, inverse_of: :report_elements, optional: true, class_name: 'RepositoryBase'
2016-02-12 16:52:43 +01:00
2021-06-10 10:59:34 +02:00
scope :active, -> { where(type_of: Extends::ACTIVE_REPORT_ELEMENTS) }
2016-07-21 13:11:15 +02:00
end