# Preventing auto-save of related model objects

**URL:** <https://www.ruby-forum.com/t/preventing-auto-save-of-related-model-objects/90244>\
**Category:** Rails\
**Created:** [March 27, 2007, 1:25am UTC](https://www.ruby-forum.com/t/preventing-auto-save-of-related-model-objects/90244 "2007-03-27T01:25:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chopper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@chopper](https://www.ruby-forum.com/u/chopper)\
**Post date:** [March 27, 2007, 1:25am UTC](https://www.ruby-forum.com/t/preventing-auto-save-of-related-model-objects/90244/1 "2007-03-27T01:25:22Z")

</div>

How do you prevent Rails from saving many-to-many updates on a model  
object?

I have an edit page for a model object which has a table on it  
represented  
by a has-many relationship. Each table row consists of a label and a  
series  
of checkboxes. I am trying to allow the user to add/remove rows from  
this  
table (using AJAX), but then either Cancel or Save the updates along  
with  
the rest of the info on the page.

Whenever the AJAX calls update the backing model, the relationships are  
saved in the database rather than held in memory. Is there a way to  
prevent  
this, or enable some sort of transaction across http requests, that can  
rollback in the case of a cancel?

Or is there a better way to accomplish this?

Thanks,

- chopper

---

<div class="post-metadata">

**Author:** ![chopper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@chopper](https://www.ruby-forum.com/u/chopper)\
**Post date:** [March 28, 2007, 12:16am UTC](https://www.ruby-forum.com/t/preventing-auto-save-of-related-model-objects/90244/2 "2007-03-28T00:16:20Z")

</div>

On Mar 27, 11:24 am, chopper [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> this, or enable some sort of transaction across http requests, that can  
> rollback in the case of a cancel?
> 
> Or is there a better way to accomplish this?
> 
> Thanks,
> 
> - chopper

Transactions across http requests would be a bad thing. How do you  
guarantee commit/rollback happens, prevent records from being locked  
indefinately or records from being updated before commit/rollback?

I’m not a ruby expert but I am working on a similar problem and I  
posted a question about this 2 weeks ago and got no responses.

I am interested to see how you are handling the many to many in your  
rhtml and controller.

If you post your rhtml file and the relevent controller functions I  
may be able to help.

Cheers  
Reed
