This project is archived and is in readonly mode.

#347 ✓wontfix
Ruy Asan

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

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

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

Comments and changes to this ticket

  • Ruy Asan

    Ruy Asan June 5th, 2008 @ 10:50 PM

    Apparently some people actually enjoy working with diffs ;)

  • Pratik

    Pratik June 9th, 2008 @ 11:38 AM

    • 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.

  • Ruy Asan

    Ruy Asan June 12th, 2008 @ 03:33 AM

    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.

  • Tony Ennis

    Tony Ennis July 15th, 2008 @ 04:12 PM

    • 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

  • Tony Ennis

    Tony Ennis July 15th, 2008 @ 04:14 PM

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

  • Alberto Perdomo

    Alberto Perdomo September 2nd, 2008 @ 10:14 PM

    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...

  • Pratik

    Pratik October 13th, 2008 @ 05:55 PM

    • State changed from “incomplete” to “wontfix”

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

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>

People watching this ticket

Pages