This project is archived and is in readonly mode.

#5339 ✓invalid
Neeraj Singh

autosave behavior not consistent between has_many and has_one

Reported by Neeraj Singh | August 9th, 2010 @ 04:08 PM | in 3.x

I have described the problem in detail in this blog. http://neeraj.name/2010/08/09/autosave-option-in-rails.html

Comments and changes to this ticket

  • Neeraj Singh

    Neeraj Singh August 9th, 2010 @ 05:03 PM

    • Assigned user set to “Neeraj Singh”
  • José Valim

    José Valim August 9th, 2010 @ 06:35 PM

    • State changed from “new” to “invalid”

    The inconsistency is not in :autosave, but the fact :validate is true by default for has_many but false for has_one. It works this way for a long time (I'm not aware of the reason) but I'm sure we cannot change the default as it will cause massive breakage.

  • Neeraj Singh

    Neeraj Singh August 9th, 2010 @ 06:48 PM

    Don't worry that in has_one because of lack of validation invalid record will get in. That won't happen. Validation still happens.

    • if autosave is not declared
    • if child is invalid
    • then has_one will persist the parent record but reject child record.
    • then has_many will reject both parent and child record.

    That's the inconsistency.

    Just wanted to clarify that in both the cases invalid record will not get persisted :-)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages