Sha256: e2a32456ce6a1b9fd2e9b396650c9c5d1a3cca6672102d4ae966c099e1a93a9b

Contents?: true

Size: 650 Bytes

Versions: 63

Compression:

Stored size: 650 Bytes

Contents

# frozen_string_literal: true

module Spree
  class Taxonomy < Spree::Base
    acts_as_list

    validates :name, presence: true

    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.whitelisted_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

63 entries across 63 versions & 1 rubygems

Version Path
solidus_core-3.2.9 app/models/spree/taxonomy.rb
solidus_core-3.2.8 app/models/spree/taxonomy.rb
solidus_core-3.2.7 app/models/spree/taxonomy.rb
solidus_core-3.2.6 app/models/spree/taxonomy.rb
solidus_core-3.1.9 app/models/spree/taxonomy.rb
solidus_core-3.2.5 app/models/spree/taxonomy.rb
solidus_core-3.2.4 app/models/spree/taxonomy.rb
solidus_core-3.2.3 app/models/spree/taxonomy.rb
solidus_core-3.1.8 app/models/spree/taxonomy.rb
solidus_core-3.0.8 app/models/spree/taxonomy.rb
solidus_core-3.2.2 app/models/spree/taxonomy.rb
solidus_core-3.2.1 app/models/spree/taxonomy.rb
solidus_core-3.2.0 app/models/spree/taxonomy.rb
solidus_core-3.2.0.alpha app/models/spree/taxonomy.rb
solidus_core-3.0.7 app/models/spree/taxonomy.rb
solidus_core-2.11.17 app/models/spree/taxonomy.rb
solidus_core-3.1.7 app/models/spree/taxonomy.rb
solidus_core-2.11.16 app/models/spree/taxonomy.rb
solidus_core-3.0.6 app/models/spree/taxonomy.rb
solidus_core-3.1.6 app/models/spree/taxonomy.rb