Sha256: 2c46e1b5069c687a584f4279c82c4418c805aaa0e813dafb4973775fbb8308e2

Contents?: true

Size: 567 Bytes

Versions: 14

Compression:

Stored size: 567 Bytes

Contents

module Spree
  class Taxonomy < ActiveRecord::Base
    validates :name, presence: true

    attr_accessible :name

    has_many :taxons
    has_one :root, conditions: { 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_column(:name, name)
        else
          self.root = Taxon.create!({ taxonomy_id: id, name: name }, without_protection: true)
        end
      end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spree_core-2.0.12 app/models/spree/taxonomy.rb
spree_core-2.0.11 app/models/spree/taxonomy.rb
spree_core-2.0.10 app/models/spree/taxonomy.rb
spree_core-2.0.9 app/models/spree/taxonomy.rb
spree_core-2.0.8 app/models/spree/taxonomy.rb
spree_core-2.0.7 app/models/spree/taxonomy.rb
spree_core-2.0.6 app/models/spree/taxonomy.rb
spree_core-2.0.5 app/models/spree/taxonomy.rb
spree_core-2.0.4 app/models/spree/taxonomy.rb
spree_core-2.0.3 app/models/spree/taxonomy.rb
spree_core-2.0.2 app/models/spree/taxonomy.rb
spree_core-2.0.1 app/models/spree/taxonomy.rb
spree_core-2.0.0 app/models/spree/taxonomy.rb
spree_core-2.0.0.rc1 app/models/spree/taxonomy.rb