From 8fd86fbdf79ed75f27d6ad805ea1de627de3de78 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Tue, 21 Nov 2023 10:55:22 -0600 Subject: [PATCH] FIX: Preserve custom field array order (#24491) --- app/models/concerns/has_custom_fields.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/has_custom_fields.rb b/app/models/concerns/has_custom_fields.rb index 0678d45c553..e543d8c97ed 100644 --- a/app/models/concerns/has_custom_fields.rb +++ b/app/models/concerns/has_custom_fields.rb @@ -72,6 +72,7 @@ module HasCustomFields klass .where(foreign_key => ids, :name => allowed_fields) + .order(:id) .pluck(foreign_key, :name, :value) .each do |cf| result[cf[0]] ||= {} @@ -111,6 +112,7 @@ module HasCustomFields "#{name}CustomField" .constantize + .order(:id) .where("#{fk} in (?)", map.keys) .where("name in (?)", fields) .pluck(fk, :name, :value) @@ -301,7 +303,7 @@ module HasCustomFields def refresh_custom_fields_from_db target = HashWithIndifferentAccess.new _custom_fields - .order("id asc") + .order(:id) .pluck(:name, :value) .each { |key, value| self.class.append_custom_field(target, key, value) } @custom_fields_orig = target