Prevent mutation of unsaved AR collections by Marshal#dump

A patch for preventing Marshal#dump bug from https://github.com/rails/rails/pull/9705