Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

access project custom field mapping using association instead of directly in bulk update service

Ivan Kuchin86347745920b
diff --git a/app/services/project_custom_field_project_mappings/bulk_update_service.rb b/app/services/project_custom_field_project_mappings/bulk_update_service.rb
index 4ec6f4c33eb..90a8c41bb13 100644
--- a/app/services/project_custom_field_project_mappings/bulk_update_service.rb
+++ b/app/services/project_custom_field_project_mappings/bulk_update_service.rb
@@ -88,25 +88,23 @@ module ProjectCustomFieldProjectMappings
end
def disable_custom_fields(custom_field_ids)
- ProjectCustomFieldProjectMapping
- .where(project_id: @project.id, custom_field_id: custom_field_ids)
+ @project.project_custom_field_project_mappings
+ .where(custom_field_id: custom_field_ids)
.delete_all
end
def existing_mappings(custom_field_ids)
- ProjectCustomFieldProjectMapping
- .where(project_id: @project.id, custom_field_id: custom_field_ids)
+ @project.project_custom_field_project_mappings
+ .where(custom_field_id: custom_field_ids)
.pluck(:custom_field_id)
end
def create_mappings(custom_field_ids)
- new_mappings = custom_field_ids.map do |id|
- { project_id: @project.id, custom_field_id: id }
- end
- ProjectCustomFieldProjectMapping.insert_all(
- new_mappings,
- unique_by: %i[project_id custom_field_id]
- )
+ @project.project_custom_field_project_mappings
+ .insert_all(
+ custom_field_ids.map { |id| { custom_field_id: id } },
+ unique_by: %i[project_id custom_field_id]
+ )
end
end
end