Sha256: 7fe899109d1c68fbe606fb2265f5ca8e3b738ae8d20803ed83af65f1536c627a

Contents?: true

Size: 570 Bytes

Versions: 23

Compression:

Stored size: 570 Bytes

Contents

module Spree
  class Taxonomy < Spree::Base
    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("#{self.table_name}.position") }

    private
      def set_name
        if root
          root.update_columns(
            name: name,
            updated_at: Time.now,
          )
        else
          self.root = Taxon.create!(taxonomy_id: id, name: name)
        end
      end

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
spree_core-2.3.13 app/models/spree/taxonomy.rb
spree_core-2.3.12 app/models/spree/taxonomy.rb
spree_core-2.3.11 app/models/spree/taxonomy.rb
spree_core-2.3.10 app/models/spree/taxonomy.rb
spree_core-2.3.9 app/models/spree/taxonomy.rb
spree_core-2.3.8 app/models/spree/taxonomy.rb
spree_core-2.4.5 app/models/spree/taxonomy.rb
spree_core-2.4.4 app/models/spree/taxonomy.rb
spree_core-2.3.7 app/models/spree/taxonomy.rb
spree_core-2.4.3 app/models/spree/taxonomy.rb
spree_core-2.4.2 app/models/spree/taxonomy.rb
spree_core-2.3.6 app/models/spree/taxonomy.rb
spree_core-2.4.1 app/models/spree/taxonomy.rb
spree_core-2.4.0 app/models/spree/taxonomy.rb
spree_core-2.3.5 app/models/spree/taxonomy.rb
spree_core-2.4.0.rc3 app/models/spree/taxonomy.rb
spree_core-2.4.0.rc2 app/models/spree/taxonomy.rb
spree_core-2.4.0.rc1 app/models/spree/taxonomy.rb
spree_core-2.3.4 app/models/spree/taxonomy.rb
spree_core-2.3.3 app/models/spree/taxonomy.rb