Skip to content

Instantly share code, notes, and snippets.

@liwh
Created September 5, 2011 13:49
Show Gist options
  • Save liwh/1195027 to your computer and use it in GitHub Desktop.
Save liwh/1195027 to your computer and use it in GitHub Desktop.
rails 3.1 changelog for dup method
# ActiveRecord::Base#dup and ActiveRecord::Base#clone semantics have changed to closer match normal Ruby dup and clone semantics.
# Calling ActiveRecord::Base#clone will result in a shallow copy of the record, including copying the frozen state. No callbacks will be called.
# Calling ActiveRecord::Base#dup will duplicate the record, including calling after initialize hooks. Frozen state will not be copied, and all associations will be cleared. A duped record will return true for new_record?, have a nil id field, and is saveable.
@ssoulless
Copy link

object = Object.find 1 #or whatever
duplicate = object.dup
box.objects << duplicate

Well explained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment