From 04c1cf2fb9aa545cbfd80afabd5cad0a51f2190f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 8 Apr 2019 00:11:11 +0200 Subject: [PATCH] Followup for commit b1b137bb0da5dd3329f90d4bdd5e5122630feceb - verify if object manager attribute exists for user only (not locale for any other object). --- .../20190328000000_rename_locale_on_users.rb | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/db/migrate/20190328000000_rename_locale_on_users.rb b/db/migrate/20190328000000_rename_locale_on_users.rb index f7f251c8a..af3e3e7cb 100644 --- a/db/migrate/20190328000000_rename_locale_on_users.rb +++ b/db/migrate/20190328000000_rename_locale_on_users.rb @@ -4,13 +4,29 @@ class RenameLocaleOnUsers < ActiveRecord::Migration[5.1] return if ActiveRecord::Base.connection.columns('users').map(&:name).exclude?('locale') ActiveRecord::Migration.rename_column(:users, :locale, :_locale) - ObjectManager::Attribute.find_by(name: 'locale').update(name: '_locale') + User.reset_column_information + + attribute = ObjectManager::Attribute.get( + object: 'User', + name: 'locale', + ) + return if !attribute + + attribute.update(name: '_locale') end def down return if ActiveRecord::Base.connection.columns('users').map(&:name).exclude?('_locale') ActiveRecord::Migration.rename_column(:users, :_locale, :locale) - ObjectManager::Attribute.find_by(name: '_locale').update(name: 'locale') + User.reset_column_information + + attribute = ObjectManager::Attribute.get( + object: 'User', + name: '_locale', + ) + return if !attribute + + attribute.update(name: 'locale') end end