2017-06-23 21:19:08 +08:00
|
|
|
class CustomField < ApplicationRecord
|
2016-09-21 21:35:23 +08:00
|
|
|
auto_strip_attributes :name, nullify: false
|
2016-02-12 23:52:43 +08:00
|
|
|
validates :name,
|
2016-09-21 21:35:23 +08:00
|
|
|
presence: true,
|
2016-10-05 23:45:20 +08:00
|
|
|
length: { maximum: Constants::NAME_MAX_LENGTH },
|
2017-01-24 23:34:21 +08:00
|
|
|
uniqueness: { scope: :team, case_sensitive: true },
|
2016-09-21 22:15:56 +08:00
|
|
|
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
|
|
|
|
'Sample group', 'Added on', 'Added by'] }
|
2017-01-24 23:34:21 +08:00
|
|
|
validates :user, :team, presence: true
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2017-06-28 21:21:32 +08:00
|
|
|
belongs_to :user, inverse_of: :custom_fields, optional: true
|
|
|
|
belongs_to :team, inverse_of: :custom_fields, optional: true
|
2016-09-21 22:15:56 +08:00
|
|
|
belongs_to :last_modified_by,
|
|
|
|
foreign_key: 'last_modified_by_id',
|
2017-06-28 21:21:32 +08:00
|
|
|
class_name: 'User',
|
|
|
|
optional: true
|
2016-12-09 18:58:10 +08:00
|
|
|
has_many :sample_custom_fields, inverse_of: :custom_field, dependent: :destroy
|
2016-12-07 23:37:16 +08:00
|
|
|
|
2016-12-08 00:43:00 +08:00
|
|
|
after_create :update_samples_table_state
|
2016-12-08 00:25:42 +08:00
|
|
|
|
|
|
|
def update_samples_table_state
|
2016-12-14 22:23:00 +08:00
|
|
|
SamplesTable.update_samples_table_state(self, nil)
|
2016-12-07 23:37:16 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|