Sha256: 8a949faaf4d7440a5f4328a2cf86eda820b784e741512406f9437b81528a0375

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

##
# Category 是分类。

class Unidom::Category::Category < Unidom::Category::ApplicationRecord

  self.table_name = 'unidom_categories'

  include Unidom::Common::Concerns::ModelExtension
  include Unidom::Category::Concerns::AsCategory
  include Unidom::Category::Concerns::AsAncestorCategory
  include Unidom::Category::Concerns::AsDescendantCategory

  validates :name,         presence:    true, length: { in: 2..self.columns_hash['name'].limit         }
  validates :abbreviation, allow_blank: true, length: { in: 2..self.columns_hash['abbreviation'].limit }

  belongs_to :scheme, class_name: 'Unidom::Category::CategoryScheme', foreign_key: :scheme_id

  scope :scheme_is,          ->(scheme) { where scheme_id: to_id(scheme)                                      }
  scope :code_length_is,     ->(length) { where 'LENGTH(code) = :code_length',  code_length:       length     }
  scope :code_starting_with, ->(prefix) { where 'code LIKE :prefix_expression', prefix_expression: prefix+'%' }

end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Category::Category'

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
unidom-category-2.0 app/models/unidom/category/category.rb
unidom-category-1.6.8 app/models/unidom/category/category.rb
unidom-category-1.6.7 app/models/unidom/category/category.rb
unidom-category-1.6.6 app/models/unidom/category/category.rb
unidom-category-1.6.5 app/models/unidom/category/category.rb
unidom-category-1.6.4 app/models/unidom/category/category.rb
unidom-category-1.6.3 app/models/unidom/category/category.rb