Skip to content

Commit 36e5b7d

Browse files
author
John Pinto
committed
Fix for bug in Plan duplication results in original plan identifier being copied.
Change in class method Plan.deep_copy: - Firstly, on duplicating the Plan we set the plan identifier to nil and save. - Then we fill the identifier variable with the Plan id that was regenerated when the duplicate copy was save in the previous. - We then persist this change by saving the Plan again.
1 parent 56759df commit 36e5b7d

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### Fixed
4+
- Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field.
5+
36
## v4.2.0
47

58
**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**

app/models/plan.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ def self.deep_copy(plan)
254254
plan_copy = plan.dup
255255
plan_copy.title = "Copy of #{plan.title}"
256256
plan_copy.feedback_requested = false
257+
# Don't copy the identifier as it will be regenerated
258+
plan_copy.identifier = nil
257259
plan_copy.save!
260+
# Copy newly generated Id to the identifier
261+
plan_copy.identifier = plan_copy.id
262+
plan.save!
258263
plan.answers.each do |answer|
259264
answer_copy = Answer.deep_copy(answer)
260265
answer_copy.plan_id = plan_copy.id

0 commit comments

Comments
 (0)