Sha256: 992b175427707761b30999704badcadfd39726b9752ccdcfd2fd6e2477c3ca8c

Contents?: true

Size: 632 Bytes

Versions: 39

Compression:

Stored size: 632 Bytes

Contents

module Spree
  class Taxonomy < Spree::Base
    acts_as_list

    validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true }

    has_many :taxons, inverse_of: :taxonomy
    has_one :root, -> { where parent_id: nil }, class_name: 'Spree::Taxon', dependent: :destroy

    after_create :set_root
    after_save :set_root_taxon_name

    default_scope { order("#{table_name}.position, #{table_name}.created_at") }

    private

    def set_root
      self.root ||= Taxon.create!(taxonomy_id: id, name: name)
    end

    def set_root_taxon_name
      root.update_attributes(name: name)
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
spree_core-3.7.14.1 app/models/spree/taxonomy.rb
spree_core-3.7.14 app/models/spree/taxonomy.rb
spree_core-3.7.13 app/models/spree/taxonomy.rb
spree_core-3.7.12 app/models/spree/taxonomy.rb
spree_core-3.7.11 app/models/spree/taxonomy.rb
spree_core-3.4.6 app/models/spree/taxonomy.rb
spree_core-3.7.10 app/models/spree/taxonomy.rb
spree_core-3.7.9 app/models/spree/taxonomy.rb
spree_core-3.7.8 app/models/spree/taxonomy.rb
spree_core-3.7.7 app/models/spree/taxonomy.rb
spree_core-3.7.6 app/models/spree/taxonomy.rb
spree_core-3.7.5 app/models/spree/taxonomy.rb
spree_core-3.7.4 app/models/spree/taxonomy.rb
spree_core-3.7.3 app/models/spree/taxonomy.rb
spree_core-3.7.2 app/models/spree/taxonomy.rb
spree_core-3.7.1 app/models/spree/taxonomy.rb
spree_core-3.7.0 app/models/spree/taxonomy.rb
spree_core-3.7.0.rc3 app/models/spree/taxonomy.rb
spree_core-3.7.0.rc2 app/models/spree/taxonomy.rb
spree_core-3.7.0.rc1 app/models/spree/taxonomy.rb