2016-02-12 23:52:43 +08:00
|
|
|
class CustomField < ActiveRecord::Base
|
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,
|
|
|
|
length: { maximum: NAME_MAX_LENGTH },
|
2016-09-21 22:15:56 +08:00
|
|
|
uniqueness: { scope: :organization, case_sensitive: true },
|
|
|
|
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
|
|
|
|
'Sample group', 'Added on', 'Added by'] }
|
2016-02-12 23:52:43 +08:00
|
|
|
validates :user, :organization, presence: true
|
|
|
|
|
|
|
|
belongs_to :user, inverse_of: :custom_fields
|
|
|
|
belongs_to :organization, inverse_of: :custom_fields
|
2016-09-21 22:15:56 +08:00
|
|
|
belongs_to :last_modified_by,
|
|
|
|
foreign_key: 'last_modified_by_id',
|
|
|
|
class_name: 'User'
|
2016-02-12 23:52:43 +08:00
|
|
|
has_many :sample_custom_fields, inverse_of: :custom_field
|
|
|
|
end
|