Skip to content

Commit

Permalink
Fix for bug in Plan duplication results in original plan identifier b…
Browse files Browse the repository at this point in the history
…eing 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.
  • Loading branch information
John Pinto committed Jul 29, 2024
1 parent 56759df commit 36e5b7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Fixed
- 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.

## v4.2.0

**Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.**
Expand Down
5 changes: 5 additions & 0 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ def self.deep_copy(plan)
plan_copy = plan.dup
plan_copy.title = "Copy of #{plan.title}"
plan_copy.feedback_requested = false
# Don't copy the identifier as it will be regenerated
plan_copy.identifier = nil
plan_copy.save!
# Copy newly generated Id to the identifier
plan_copy.identifier = plan_copy.id
plan.save!
plan.answers.each do |answer|
answer_copy = Answer.deep_copy(answer)
answer_copy.plan_id = plan_copy.id
Expand Down

0 comments on commit 36e5b7d

Please sign in to comment.