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.2 app/models/spree/taxonomy.rb
spree_core-2.3.1 app/models/spree/taxonomy.rb
spree_core-2.3.0 app/models/spree/taxonomy.rb