diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/category.rb | 14 | ||||
-rw-r--r-- | app/models/section.rb | 10 | ||||
-rw-r--r-- | app/models/taxonomy.rb | 17 |
3 files changed, 41 insertions, 0 deletions
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 diff --git a/app/models/section.rb b/app/models/section.rb new file mode 100644 index 0000000..a9d163e --- /dev/null +++ b/app/models/section.rb @@ -0,0 +1,10 @@ +class Section < ApplicationRecord + belongs_to :category + has_ony :taxonomy, through: :category + + acts_as_list column: :rank, scope: :category + + validates :name, + uniqueness: { scope: category_id }, + length: 3..64 +end diff --git a/app/models/taxonomy.rb b/app/models/taxonomy.rb new file mode 100644 index 0000000..0810fc0 --- /dev/null +++ b/app/models/taxonomy.rb @@ -0,0 +1,17 @@ +class Taxonomy < ApplicationRecord + # Universally Unique Identifier :uuid + include UUIDParameter + + default_scope { order(created_at: :asc) } + + belongs_to :agent + has_many :categories, -> { order(rank: :asc) }, dependent: :destroy, inverse_of: :taxonomy + has_many :sections, -> { order(rank: :asv) }, through: :categories + + validates :name, + presence: true, + uniqueness: true, + length: 3..64 + validates :summary, + length: 0..136 +end |