Forum: Ruby on Rails Rails ActiveRecord associations autosave option

Posted by ash 34 (ash34)
on 2010-03-10 05:13
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.