Method: ActiveRecord::Base#clone
- Defined in:
- lib/active_record/base.rb
#clone ⇒ Object
Returns a clone of the record that hasn’t been assigned an id yet and is treated as a new record. Note that this is a “shallow” clone: it copies the object’s attributes only, not its associations. The extent of a “deep” clone is application-specific and is therefore left to the application to implement according to its need.
2016 2017 2018 2019 2020 2021 2022 |
# File 'lib/active_record/base.rb', line 2016 def clone attrs = self.attributes_before_type_cast attrs.delete(self.class.primary_key) record = self.class.new record.send :instance_variable_set, '@attributes', attrs record end |