Files
openfoodnetwork/app/models/spree/taxonomy.rb
Matt-Yorkley 0e82160b76 Touch the updated_at column when updating records via #update_column
#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
2021-01-30 12:49:38 +00:00

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