Skip to content

Instantly share code, notes, and snippets.

@ericsaboia
Created May 27, 2011 03:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ericsaboia/994614 to your computer and use it in GitHub Desktop.
Save ericsaboia/994614 to your computer and use it in GitHub Desktop.
Changelog ActiveRecord:Base Rails 3.1
# 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.
@adilwali
Copy link

adilwali commented Mar 6, 2013

Well described.

@ratbeard
Copy link

copied_plan = test_plan.dup
copied_plan.is_shared = false
self.test_plans << copied_plan

@tambakoo
Copy link

I have to create associated objects manually with a command. Should't I get all associations directly with dup ?

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