2017-05-16 21:27:36 +08:00
|
|
|
class RepositoryCell < ActiveRecord::Base
|
|
|
|
belongs_to :repository_row
|
|
|
|
belongs_to :repository_column
|
|
|
|
belongs_to :value, polymorphic: true, dependent: :destroy
|
|
|
|
|
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
|
2017-07-20 17:44:10 +08:00
|
|
|
validates :repository_row,
|
2018-01-17 19:54:32 +08:00
|
|
|
uniqueness: { scope: :repository_column }
|
2017-05-16 21:27:36 +08:00
|
|
|
|
|
|
|
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
|