diff options
Diffstat (limited to 'activerecord/test/models/lesson.rb')
-rw-r--r-- | activerecord/test/models/lesson.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/models/lesson.rb b/activerecord/test/models/lesson.rb new file mode 100644 index 0000000000..e546339689 --- /dev/null +++ b/activerecord/test/models/lesson.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class LessonError < Exception +end + +class Lesson < ActiveRecord::Base + has_and_belongs_to_many :students + before_destroy :ensure_no_students + + def ensure_no_students + raise LessonError unless students.empty? + end +end |