# Rails ActiveRecord associations autosave option

**URL:** <https://www.ruby-forum.com/t/rails-activerecord-associations-autosave-option/184894>\
**Category:** Rails\
**Created:** [March 10, 2010, 5:13am UTC](https://www.ruby-forum.com/t/rails-activerecord-associations-autosave-option/184894 "2010-03-10T05:13:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ash34](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@ash34](https://www.ruby-forum.com/u/ash34)\
**Post date:** [March 10, 2010, 5:13am UTC](https://www.ruby-forum.com/t/rails-activerecord-associations-autosave-option/184894/1 "2010-03-10T05:13:38Z")

</div>

I have the following associations.

class Document \< ActiveRecord::Base  
has\_many :document\_sections, :dependent =\> :destroy, :autosave =\> true  
has\_many :document\_items, :through =\> :document\_sections  
end

class DocumentSection \< ActiveRecord::Base  
belongs\_to :document  
has\_many :document\_items, :dependent =\> :destroy, :autosave =\> true  
end

class DocumentItem \< ActiveRecord::Base  
belongs\_to :document\_section  
end

When I use irb console to do

d = Document.find\_by\_id(100)  
d.title = ‘1-comments’  
s = d.document\_sections.find\_by\_id(200)  
s.title = ‘2-comments’  
i = s.document\_items.find\_by\_id(10)  
i.comments = ‘3-comments’  
d.save

The changes to d, s, and i get saved to the database because of the  
autosave option set to true in the model. However when I do the same in  
a controller action, only the document header comments get saved. The  
log only shows a sql update to the documents table but not the  
document\_sections and document\_items table. Why is this behavior  
different in a controller vs irb console.
