Sha256: d115aedc31f79f3b5b48d567f56013597d19210823630d97e2108e25144c6fcd
Contents?: true
Size: 737 Bytes
Versions: 7
Compression:
Stored size: 737 Bytes
Contents
# frozen_string_literal: true module Spree class Taxonomy < Spree::Base acts_as_list validates :name, presence: true validates :name, uniqueness: true, if: -> { Spree::Config.extra_taxonomy_validations } has_many :taxons, inverse_of: :taxonomy has_one :root, -> { where parent_id: nil }, class_name: "Spree::Taxon", dependent: :destroy after_save :set_name default_scope -> { order(position: :asc) } self.allowed_ransackable_attributes = %w[name] private def set_name if root root.update_columns( name: name, updated_at: Time.current ) else self.root = Spree::Taxon.create!(taxonomy_id: id, name: name) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems