# .sync() for ActiveRecord objects

**URL:** <https://www.ruby-forum.com/t/sync-for-activerecord-objects/74951>\
**Category:** Rails\
**Created:** [November 7, 2006, 11:03am UTC](https://www.ruby-forum.com/t/sync-for-activerecord-objects/74951 "2006-11-07T11:03:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/dbc845/32.png) [@yeah](https://www.ruby-forum.com/u/yeah)\
**Post date:** [November 7, 2006, 11:03am UTC](https://www.ruby-forum.com/t/sync-for-activerecord-objects/74951/1 "2006-11-07T11:03:59Z")

</div>

Hi everybody,

the other day, I thought it may be useful to have a .sync() method on  
ActiveRecord objects. The behavior would be something between a  
.reload() and a .save().

- At every reload, an internal hash would store the attributes as they  
were in the db at reload time (think svn’s working-base)
- whenever attributes are changed on the object, the values of that  
hash would remain untouched
- whenever sync is called, the tuple gets reloaded from the db and both  
the current db tuple and the current object attribute values are  
compared to the working-base hash. if changes were made on the object,  
they get populated to the db and vice versa.
- conflicts could result in exceptions or there could be defaults like  
so:  
my\_object.sync :on\_conflict\_follow =\> :database

I didn’t have time to implement this so far, but I wanted to share this  
idea and get feedback. What do you think?

Bests

Jan

---

<div class="post-metadata">

**Author:** ![yeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/dbc845/32.png) [@yeah](https://www.ruby-forum.com/u/yeah)\
**Post date:** [November 7, 2006, 11:05am UTC](https://www.ruby-forum.com/t/sync-for-activerecord-objects/74951/2 "2006-11-07T11:05:08Z")

</div>

check out acts\_as\_modified plugin

[http://svn.viney.net.nz/things/rails/plugins/acts\_as\_modified/](http://svn.viney.net.nz/things/rails/plugins/acts_as_modified/)

Chris
