
save with invalid child still saves parent (and appears valid)
Reported by Martin Emde | January 12th, 2010 @ 02:35 PM
Here's what I'm seeing:
obj = Obj.new(attrs)
child = obj.children.new(invalid_attrs)
obj.valid? # => true
obj.save # => false
obj.new? # => false
child.new? # => true
I would expect the obj to be rolled back if the child does not save. Is this the intended behavior?
Comments and changes to this ticket
-
Dan Kubb (dkubb) February 5th, 2010 @ 02:59 AM
- State changed from new to unconfirmed
Can you provide a stand-alone script that reproduces this problem?
-
Martin Gamsjaeger (snusnu) February 5th, 2010 @ 12:27 PM
- Milestone set to 1.0.0
- Tag changed from save, transaction, validation to save, validation
- State changed from unconfirmed to confirmed
Dan,
I ran into this today (and was able to workaround with contextual validations)
See http://pastie.org/811390 for a standalone
I guess this is a case for proper validation support of has 1..n and the likes. I would expect has n to behave like has 0..n so the above standalone is probably correct behavior. To support Martin's usecase (and ours) we would need proper validations for stuff like has 1..n, ensuring that at least one child is present.
-
Dan Kubb (dkubb) May 26th, 2010 @ 01:20 AM
- Milestone cleared.
-
Piotr Solnica (solnic) May 17th, 2011 @ 02:30 AM
- Tag changed from save, validation to dm-validations, save, validation
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »