Sha256: 331baee9bdf45c9e4012fd6778facba981e92eba5a10c49fc6676a4b9b33ee8b

Contents?: true

Size: 422 Bytes

Versions: 9

Compression:

Stored size: 422 Bytes

Contents

class Taxonomy < ActiveRecord::Base

  validates :name, :presence => true

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

  after_save :set_name

  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

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-0.70.7 app/models/taxonomy.rb
spree_core-0.70.6 app/models/taxonomy.rb
spree_core-0.70.5 app/models/taxonomy.rb
spree_core-0.70.4 app/models/taxonomy.rb
spree_core-0.70.3 app/models/taxonomy.rb
spree_core-0.70.2 app/models/taxonomy.rb
spree_core-0.70.1 app/models/taxonomy.rb
spree_core-0.70.0 app/models/taxonomy.rb
spree_core-0.70.0.rc2 app/models/taxonomy.rb