scinote-web/app/models/report_element.rb

39 lines
1.4 KiB
Ruby
Raw Normal View History

2019-05-09 23:10:02 +08:00
# frozen_string_literal: true
2017-06-23 21:19:08 +08:00
class ReportElement < ApplicationRecord
enum type_of: Extends::REPORT_ELEMENT_TYPES
2016-02-12 23:52:43 +08: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 23:10:02 +08:00
belongs_to :report, inverse_of: :report_elements
2016-02-12 23:52:43 +08:00
# Hierarchical structure representation
2017-03-09 17:51:54 +08:00
has_many :children,
2021-05-27 22:31:41 +08:00
-> { order(:position) },
2017-03-09 17:51:54 +08:00
class_name: 'ReportElement',
foreign_key: 'parent_id',
dependent: :destroy
2017-06-28 21:21:32 +08:00
belongs_to :parent, class_name: 'ReportElement', optional: true
2016-02-12 23:52:43 +08:00
# References to various report entities
2017-06-28 21:21:32 +08: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 16:59:34 +08:00
belongs_to :repository, inverse_of: :report_elements, optional: true, class_name: 'RepositoryBase'
2016-02-12 23:52:43 +08:00
2021-06-10 16:59:34 +08:00
scope :active, -> { where(type_of: Extends::ACTIVE_REPORT_ELEMENTS) }
2016-07-21 19:11:15 +08:00
end