Sha256: 4dfbcc4539150e0c45d875a309ec16c3448c4f7fd89d299b6fef5a273eaf52ed

Contents?: true

Size: 1002 Bytes

Versions: 3

Compression:

Stored size: 1002 Bytes

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: (scheme.respond_to?(:id) ? scheme.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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unidom-category-1.5.3 app/models/unidom/category/category.rb
unidom-category-1.5.2 app/models/unidom/category/category.rb
unidom-category-1.5.1 app/models/unidom/category/category.rb