mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
#update_column(s) skips callbacks (which is useful), but it doesn't change the updated_at field on the record by default (which we should be doing in these cases).
This change is made in Spree 2.2 here: b367c629ce
28 lines
564 B
Ruby
28 lines
564 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class Taxonomy < ActiveRecord::Base
|
|
validates :name, presence: true
|
|
|
|
has_many :taxons
|
|
has_one :root, -> { where parent_id: nil }, class_name: "Spree::Taxon", dependent: :destroy
|
|
|
|
after_save :set_name
|
|
|
|
default_scope -> { order("#{table_name}.position") }
|
|
|
|
private
|
|
|
|
def set_name
|
|
if root
|
|
root.update_columns(
|
|
name: name,
|
|
updated_at: Time.zone.now
|
|
)
|
|
else
|
|
self.root = Taxon.create!(taxonomy_id: id, name: name)
|
|
end
|
|
end
|
|
end
|
|
end
|