Sha256: 2daf701f41e8e11504b1516fc8fdc7a2abe4eff3808568f3a6dad4fae9046555
Contents?: true
Size: 558 Bytes
Versions: 16
Compression:
Stored size: 558 Bytes
Contents
module Spree class Taxonomy < Spree::Base acts_as_list validates :name, presence: true has_many :taxons, inverse_of: :taxonomy has_one :root, -> { where parent_id: nil }, class_name: "Spree::Taxon", dependent: :destroy after_save :set_name default_scope -> { order(:position) } private def set_name if root root.update_columns( name: name, updated_at: Time.current ) else self.root = Spree::Taxon.create!(taxonomy_id: id, name: name) end end end end
Version data entries
16 entries across 16 versions & 1 rubygems