Files
codeocean/app/models/tag.rb
2021-05-14 22:03:06 +02:00

19 lines
305 B
Ruby

# frozen_string_literal: true
class Tag < ApplicationRecord
has_many :exercise_tags
has_many :exercises, through: :exercise_tags
validates :name, uniqueness: true
before_destroy :can_be_destroyed?, prepend: true
def can_be_destroyed?
exercises.none?
end
def to_s
name
end
end