# Replace

**URL:** <https://www.ruby-forum.com/t/replace/226036>\
**Category:** Rails\
**Created:** [March 6, 2009, 10:35am UTC](https://www.ruby-forum.com/t/replace/226036 "2009-03-06T10:35:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 6, 2009, 10:35am UTC](https://www.ruby-forum.com/t/replace/226036/1 "2009-03-06T10:35:38Z")

</div>

What is the easiest way to replace record in database?

Better that this:

@old = Order.find(5)  
@new = Order.find(90)

@old.x = @new.x  
@old.y = @new.y  
@old.z = @new.z  
@old.w = @new.w  
@old.p = @new.p  
@old.r = @new.r  
…

@old.save

So now @old = @new except @old.id and @old.created\_at

---

<div class="post-metadata">

**Author:** ![giga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@giga](https://www.ruby-forum.com/u/giga)\
**Post date:** [March 6, 2009, 10:50am UTC](https://www.ruby-forum.com/t/replace/226036/2 "2009-03-06T10:50:57Z")

</div>

On Fri, Mar 6, 2009 at 10:35 AM, Fresh M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What is the easiest way to replace record in database?
> 
> Better that this:
> 
> @old = Order.find(5)  
> @new = Order.find(90)
> 
> @old.x = @new.x  
> @old.y = @new.y

@old.attributes = @new.attributes

or you can even get rid of @new completely

@old.attributes = Order.find(90).attributes

@old.save
