mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-14 21:24:54 +08:00
24 lines
934 B
Ruby
24 lines
934 B
Ruby
class CustomField < ApplicationRecord
|
|
auto_strip_attributes :name, nullify: false
|
|
validates :name,
|
|
presence: true,
|
|
length: { maximum: Constants::NAME_MAX_LENGTH },
|
|
uniqueness: { scope: :team, case_sensitive: true },
|
|
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
|
|
'Sample group', 'Added on', 'Added by'] }
|
|
validates :user, :team, presence: true
|
|
|
|
belongs_to :user, inverse_of: :custom_fields, optional: true
|
|
belongs_to :team, inverse_of: :custom_fields, optional: true
|
|
belongs_to :last_modified_by,
|
|
foreign_key: 'last_modified_by_id',
|
|
class_name: 'User',
|
|
optional: true
|
|
has_many :sample_custom_fields, inverse_of: :custom_field, dependent: :destroy
|
|
|
|
after_create :update_samples_table_state
|
|
|
|
def update_samples_table_state
|
|
SamplesTable.update_samples_table_state(self, nil)
|
|
end
|
|
end
|