diff options
Diffstat (limited to 'activerecord/test/models/lesson.rb')
-rw-r--r-- | activerecord/test/models/lesson.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/models/lesson.rb b/activerecord/test/models/lesson.rb new file mode 100644 index 0000000000..4c88153068 --- /dev/null +++ b/activerecord/test/models/lesson.rb @@ -0,0 +1,11 @@ +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 |