-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for bug in Plan duplication results in original plan identifier b… #3441
Fix for bug in Plan duplication results in original plan identifier b… #3441
Conversation
de27ebf
to
574f3bc
Compare
…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.
574f3bc
to
36e5b7d
Compare
plan_copy.save! | ||
# Copy newly generated Id to the identifier | ||
plan_copy.identifier = plan_copy.id | ||
plan.save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I tested the PR and it all appears to be behaving as it should. :) I just have a couple of thoughts as well.
The last two lines are having the final say in the saved value of plan_copy.identifier
. So assigning plan_copy.identifier = nil
prior to the first save doesn't seem necessary.
Also, plan_copy.identifier
is a String, but plan_copy.id
is an integer. I guess we have similar code in https://github.com/DMPRoadmap/roadmap/blob/main/app/controllers/plans_controller.rb#L140 (@plan.identifier = @plan.id.to_s
). However, I guess Rails is automatically typecasting the value to a String here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aaronskiba. I have made the changes suggested in a separate commit.
…eing copied. Changes (suggested by @aaronskiba): - removed an unnecessary line plan_copy.identifier = nil - cast to string the integer-valued plan id plan_copy.identifier = plan_copy.id.to_s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 👍
…eing copied.
Change in class method Plan.deep_copy: