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).
Comments and changes to this ticket
-
-
Pratik June 9th, 2008 @ 11:38 AM
- → State changed from new to incomplete
- → Assigned user changed from 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 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 =>trueI still can't get a failure.Patch with stubbornly passing tests attached.
-
Tony Ennis July 15th, 2008 @ 04:12 PM
- → Tag changed from 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 July 15th, 2008 @ 04:14 PM
Sorry previous tag is leftover from a web search. Tag should be ""
-

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 October 13th, 2008 @ 05:55 PM
- → State changed from incomplete to wontfix
This isn't needed anymore now that we have :validate option.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/rails/rails
Check out the development master (Edge Rails):
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too"..
