You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
I'm pretty sure this is a consequence of Resource#valid? only reflecting the validity of the receiver (the current resource), whereas Resource#save is dependent on the validity of loaded related Resources (relationships set on the current resource).
In my opinion, the behavior of Resource#valid? should be synchronized with Resource#save (as implied by this issue), or a new method should be introduced to check the validity of the whole resource object graph (current resource and any loaded relationships), eg., Resource#all_valid?(context) or the like.
I just encountered this problem myself.
I got a some specs to prove the broken behaviour.
First test passes, second one fails.
require'rubygems'require'data_mapper'DataMapper.setup(:default,'sqlite::memory:')classAddressincludeDataMapper::Resourceproperty:id,SerialendclassPersonincludeDataMapper::Resourceproperty:id,Serialbelongs_to:addressendclassMan < PersonendDataMapper.auto_migrate!describe'person'doit'requires address'doperson=Person.newperson.valid?person.errors[:address_id].shouldinclude("Address must not be blank")endenddescribe'man'doit'requires address'doman=Man.newman.valid?man.errors[:address_id].shouldinclude("Address must not be blank")endend
http://gist.github.com/605956
I've posted a sample there. Notice how dog is valid without a human, but save fails.
Created by pathsny (at gmail) - 2010-10-01 09:26:45 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1424
The text was updated successfully, but these errors were encountered: