Sha256: 61e6e88677bf08f59f8e8adaa793b17632bc18b7ed4f817c490d21736f85e440
Contents?: true
Size: 577 Bytes
Versions: 1
Compression:
Stored size: 577 Bytes
Contents
module Spree class Taxonomy < Spree::Base validates :name, presence: 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("#{self.table_name}.position, #{self.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spree_core-3.0.0.rc1 | app/models/spree/taxonomy.rb |