This project is archived and is in readonly mode.

#4538 ✓resolved
arash

ActiveRecord.clone does not clear out timestamps

Reported by arash | May 5th, 2010 @ 09:09 PM

The docs says that a cloned object is 'treated as a new record', however the updated_at/created_at timestamps seems to be persisted after the save! This is a bit counter intuitive.

I'm using the following monkey patch to work around this:

module ActiveRecord

class Base
  def clone_with_no_timestamps
    record = clone_without_no_timestamps
    record.updated_at = nil if record.respond_to?(:updated_at)
    record.created_at = nil if record.respond_to?(:created_at)
    record
  end

  alias_method_chain :clone, :no_timestamps
end

end

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages