Sha256: 2daf701f41e8e11504b1516fc8fdc7a2abe4eff3808568f3a6dad4fae9046555

Contents?: true

Size: 558 Bytes

Versions: 16

Compression:

Stored size: 558 Bytes

Contents

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) }

    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

16 entries across 16 versions & 1 rubygems

Version Path
solidus_core-2.4.2 app/models/spree/taxonomy.rb
solidus_core-2.3.1 app/models/spree/taxonomy.rb
solidus_core-2.4.1 app/models/spree/taxonomy.rb
solidus_core-2.2.2 app/models/spree/taxonomy.rb
solidus_core-2.4.0 app/models/spree/taxonomy.rb
solidus_core-2.4.0.rc1 app/models/spree/taxonomy.rb
solidus_core-2.4.0.beta1 app/models/spree/taxonomy.rb
solidus_core-2.3.0 app/models/spree/taxonomy.rb
solidus_core-2.3.0.rc3 app/models/spree/taxonomy.rb
solidus_core-2.3.0.rc2 app/models/spree/taxonomy.rb
solidus_core-2.3.0.rc1 app/models/spree/taxonomy.rb
solidus_core-2.3.0.beta1 app/models/spree/taxonomy.rb
solidus_core-2.2.1 app/models/spree/taxonomy.rb
solidus_core-2.2.0 app/models/spree/taxonomy.rb
solidus_core-2.2.0.rc1 app/models/spree/taxonomy.rb
solidus_core-2.2.0.beta1 app/models/spree/taxonomy.rb