Skip to content
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

model.dup should copy model values with nil public_uid #21

Merged
merged 1 commit into from Nov 3, 2022
Merged

Conversation

equivalent
Copy link
Owner

curent imlplementation:

work = Work.last
work.public_uid == 'asdfghjkl'

work_dup = model.dup
work_dup.public_uid == 'asdfghjkl' #this is wrong !!!

this should be:

work = Work.last
work.public_uid == 'asdfghjkl'

work_dup = model.dup
work_dup.public_uid == nil # this is correct !

Why?

read more: https://blog.appsignal.com/2019/02/26/diving-into-dup-and-clone.html

important part:

#dup to allow you to duplicate a record without its "internal" state (id and timestamps),

Rails implement it same way

https://github.com/rails/rails/blob/85f45350e6d3fb6284c744d36b77b79ce639dfee/activerecord/lib/active_record/timestamp.rb#L50

@equivalent equivalent merged commit 044ef91 into master Nov 3, 2022
@equivalent equivalent deleted the dup branch November 3, 2022 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant