2017-06-23 21:19:08 +08:00
|
|
|
class RepositoryCell < ApplicationRecord
|
2017-06-28 21:21:32 +08:00
|
|
|
belongs_to :repository_row, optional: true
|
|
|
|
belongs_to :repository_column, optional: true
|
|
|
|
belongs_to :value, polymorphic: true, dependent: :destroy, optional: true
|
2017-05-16 21:27:36 +08:00
|
|
|
|
2017-06-06 23:35:29 +08:00
|
|
|
validates :repository_column, presence: true
|
2017-05-16 21:27:36 +08:00
|
|
|
validate :repository_column_data_type
|
|
|
|
validates :repository_row, uniqueness: { scope: :repository_column }
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def repository_column_data_type
|
|
|
|
if value_type != repository_column.data_type
|
|
|
|
errors.add(:value_type, 'must match column data type')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|