Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

accepts_nested_attributes_for and has_one relations

#3361

when you add accepts_nested_attributes_for(:child) to a "parent" model, the "child" objects will be saved automaticly. But they are not going to be validated automaticly.
This means you will add invalid object into the database by default, since validation for child in a has_one relations are turned of by default.

I suggest to set autosave and validation to true by accepts_nested_attributes_for !!!

In our case, in combination with attachment_fu which use after-validation-callbacks to save the file, we searched a long-time to find the source why there was no file.

Reported by tim · October 9th, 2009 @ 05:56 PM

State: invalid
Milestone: 2.3.6
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran
    • Milestone set to 2.3.6
    • Assigned user set to Eloy Duran

    December 30th, 2009 @ 07:39 PM

  2. Eloy Duran
    Eloy Duran
    • State changed from new to invalid

    I wasn't able to spot this bug anymore, at least not on my current 2-3-stable and master branches. In case it still exists there, could you create a test case that demonstrates the problem?

    Closing for now, thanks.

    January 3rd, 2010 @ 09:04 PM

  3. Oleg
    Oleg

    This is a bit messed up. I'm experiencing the same issue.

    accepts_nested_attributes_for for has_one completely skips validation on the nested element. has_many works fine though.

    I'm using 2.3.5, ruby 1.8.7p173

    April 15th, 2010 @ 04:01 PM

  4. Oleg
    Oleg

    This is a bit messed up. I'm experiencing the same issue.

    accepts_nested_attributes_for for has_one completely skips validation on the nested element. has_many works fine though.

    I'm using 2.3.5, ruby 1.8.7p173

    April 15th, 2010 @ 04:01 PM

  5. Oleg
    Oleg

    never mind, I re-froze 2.3.5 and started to work. I must have frozen rails before it became 'really stable'

    April 15th, 2010 @ 04:05 PM

  6. xhming