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.

Ensure that save on child object fails for invalid belongs_to - TAKE TWO

#347

My original patch for this was quickly reverted because of this problem with circular belongs_to associations.

I added an extra unit test to check for the specific problem described in the mailing-list post, but I was not able to duplicate the error (tests pass fine with original code).

Here's the branch

Reported by Ruy Asan · June 5th, 2008 @ 10:42 PM

State: wontfix
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Ruy Asan
    Ruy Asan

    Apparently some people actually enjoy working with diffs ;)

    June 5th, 2008 @ 10:50 PM

  2. Pratik
    Pratik
    • State changed from new to incomplete
    • Assigned user set to Pratik

    First need to reproduce the old behavior :) I'm planning to add :validate => true/false option to association definition. So we can get this in after that is done.

    June 9th, 2008 @ 11:38 AM

  3. Ruy Asan
    Ruy Asan

    Looks like => true/false is now done and already covers the meat of this ticket, although even after updating my tests with belongs to =>true I still can't get a failure.

    Patch with stubbornly passing tests attached.

    June 12th, 2008 @ 03:33 AM

  4. Tony Ennis
    Tony Ennis
    • Tag set to activerecord, edge, patch, tested

    I am not sure if this is the same thing or not, but symptoms of my problem are:

    class A belongs_to B

    a = instance of A

    b = instance of B

    create a

    create b using 'a.the_belongs_to_column.create(yadda)'

    a.save!

    1. b's validation is being called

    2. the validation is failing

    3. the row is not written.

    4. a.save! does not report an error.

    5. a's row was written

    July 15th, 2008 @ 04:12 PM

  5. Tony Ennis
    Tony Ennis

    Sorry previous tag is leftover from a web search. Tag should be ""

    July 15th, 2008 @ 04:14 PM

  6. Alberto Perdomo
    Alberto Perdomo

    Hi,

    Looking up the docs in api.rubyonrails.org it seems that there was a :validate key before that used to default to false. Example:

    belongs_to :assocation, :validate => true

    But trying to use it in rails 2.1.0 returns an invalid key error.

    It seems that the validate key was removed. Why?

    In my case i am using a create_assocation call, the parent object fails validation but the child object is saved...

    September 2nd, 2008 @ 10:14 PM

  7. Pratik
    Pratik
    • State changed from incomplete to wontfix

    This isn't needed anymore now that we have :validate option.

    October 13th, 2008 @ 05:55 PM