Rails ActiveRecord associations autosave option

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs