Sha256: 992b175427707761b30999704badcadfd39726b9752ccdcfd2fd6e2477c3ca8c
Contents?: true
Size: 632 Bytes
Versions: 39
Compression:
Stored size: 632 Bytes
Contents
module Spree class Taxonomy < Spree::Base acts_as_list validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: 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("#{table_name}.position, #{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
39 entries across 39 versions & 1 rubygems