title: When will ActiveRecord save associations?
body: <ol>
  <li><p>I know that it will save associations when <code>autosave: true</code> as per <a href="https://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html" rel="nofollow noreferrer">https://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html</a></p>
  </li>
  <li><p>I know that it will save associations that are constructed like</p>
  </li>
  </ol>
  <pre><code>book = Book.new(name: 'foo')
  book.authors.build(name: 'bar') #has_many
  book.save
  </code></pre>
  <p>or like</p>
  <pre><code>book = Book.new(name: 'foo')
  book.build_author(name: 'bar') #has_one
  book.save
  </code></pre>
  <ol start="3">
  <li>I think associations are also saved when they are assigned or added</li>
  </ol>
  <pre><code>book = Book.new(name: 'foo')
  book.author = Author.new(name: 'bar')
  book.save
  </code></pre>
  <p>or</p>
  <pre><code>book = Book.new(name: 'foo')
  book.authors &lt;&lt; Author.new(name: 'bar')
  book.save
  </code></pre>
  <p>But, I have a complicated bug that involves something not auto-saving when I would expect it to. So, I want to debug by inspecting <code>book</code> to verify what I think is going to be saved will actually be saved.</p>
  <p>TL; DR;
  What internal state is checked when saving associations? I'm assuming that a model has an internal instance variable like <code>associations_to_save</code> that associations get added to when they are created. Then, when the model is saved, it loops through those associations and saves them too.</p>