From 8f691b566ffbc79f1d2d7a3f67d8607cc03a789c Mon Sep 17 00:00:00 2001 From: hellekin Date: Thu, 8 Oct 2020 16:51:30 +0200 Subject: Add model foundation for classifications Taxonomy > Category > Section This commit adds models for it. https://doc.incommon.cc/#classifications --- app/models/category.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/models/category.rb (limited to 'app/models/category.rb') diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..b8c49f1 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,14 @@ +class Category < ApplicationRecord + belongs_to :taxonomy + has_many :sections, + -> { order(rank: :asc) }, + dependent: :destroy, + inverse_of: :category + + acts_as_list column: :rank, scope: :taxonomy + + validates :name, + presence: true, + uniqueness: { scope: :taxonomy_id }, + length: 3..64 +end -- cgit v1.2.3