Sha256: 44eff5afa7ad342032b19f2532d62cf122330e18bad581995969713750dee794

Contents?: true

Size: 538 Bytes

Versions: 5

Compression:

Stored size: 538 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

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

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-1.1.2 app/models/spree/taxonomy.rb
spree_core-1.1.2.rc1 app/models/spree/taxonomy.rb
spree_core-1.1.1 app/models/spree/taxonomy.rb
spree_core-1.1.0 app/models/spree/taxonomy.rb
spree_core-1.1.0.rc2 app/models/spree/taxonomy.rb