20221103181852_add_object_attribute_relation_fields_belongs_to_value.rb 754 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class AddObjectAttributeRelationFieldsBelongsToValue < ActiveRecord::Migration[6.1]
  3. def up
  4. return if !Setting.exists?(name: 'system_init_done')
  5. relation_object_attributes_belongs_to_update = [
  6. {
  7. object: 'User',
  8. name: 'organization_ids',
  9. belongs_to: 'secondary_organizations',
  10. },
  11. ]
  12. relation_object_attributes_belongs_to_update.each do |attribute|
  13. fetched_attribute = ObjectManager::Attribute.get(name: attribute[:name], object: attribute[:object])
  14. next if !fetched_attribute
  15. fetched_attribute.data_option[:belongs_to] = attribute[:belongs_to]
  16. fetched_attribute.save!
  17. end
  18. end
  19. end