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

Skip _id validation if new_record meeting was passed

Oliver Güntherb8d14bf2bca9
diff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rb
index a3558eb8157..1c0b4c519bd 100644
--- a/modules/meeting/app/models/meeting_agenda_item.rb
+++ b/modules/meeting/app/models/meeting_agenda_item.rb
@@ -45,7 +45,11 @@ class MeetingAgendaItem < ApplicationRecord
scope :with_includes_to_render, -> { includes(:author, :meeting) }
- validates :meeting_id, presence: true
+ # The primer form depends on meeting_id being validated, even though Rails pattern would suggest
+ # to validate only :meeting. When copying meetings however,
+ # we build meetings and agenda items together, so meeting_id will stay empty.
+ # We can use loaded? to check if the meeting has been provided
+ validates :meeting_id, presence: true, unless: Proc.new { |item| item.association(:meeting).loaded? && item.meeting }
validates :title, presence: true, if: Proc.new { |item| item.simple? }
validates :work_package_id, presence: true, if: Proc.new { |item| item.work_package? }, on: :create
validates :work_package_id,