Sha256: 2519af614791ca3f1a878f12286651ddb7a240f1d09f884517c50c4b6d329e1d

Contents?: true

Size: 567 Bytes

Versions: 9

Compression:

Stored size: 567 Bytes

Contents

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

    has_many :taxons
    has_one :root, :conditions => { :parent_id => nil }, :class_name => 'Spree::Taxon'

    after_save :set_name
    after_destroy :destroy_root_taxon

    private
      def set_name
        if self.root
          self.root.update_attribute(:name, self.name)
        else
          self.root = Taxon.create!({ :taxonomy_id => self.id, :name => self.name })
        end
      end

      def destroy_root_taxon
        self.root.destroy
      end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-1.0.4 app/models/spree/taxonomy.rb
spree_core-1.0.3 app/models/spree/taxonomy.rb
spree_core-1.0.2 app/models/spree/taxonomy.rb
spree_core-1.0.1 app/models/spree/taxonomy.rb
spree_core-1.0.0 app/models/spree/taxonomy.rb
spree_core-1.0.0.rc4 app/models/spree/taxonomy.rb
spree_core-1.0.0.rc3 app/models/spree/taxonomy.rb
spree_core-1.0.0.rc2 app/models/spree/taxonomy.rb
spree_core-1.0.0.rc1 app/models/spree/taxonomy.rb