crantz:  Thanks for stating the case so well :)  ORM data validation
on save is a last ditch effort to protect data integrity, just like
database constraints.  When it fails, it's an error.

If you want to know if an object is valid, call valid?.  If you want
to save an object, call save.  If either method does not do what is
expected, it's an exception.

The problem here is the save method tries to do both, and is actually
a convenience method for "valid? && save!" but the library currently
lacks a safe save method.  If you think your data has a good chance of
being invalid, and you mind the overhead of an exception, use
save_if_valid (defined to return the answer to valid? or throw an
exception).  Or more explicitly you could do:

if object.valid?
  object.save! # skips validation
else
end (1)

If you don't expect invalid data, and therefor don't want to check the
return value (just as you do with most methods), just call save (which
would throw an exception).

That said, DM is overall far better than AR :)  I'm not against
DataMapper, or I wouldn't bother to say anything.  However, I think
I'm done with this debate for now.  There is not much more to say,
except that the create method definitely needs rethinking before 1.0.

(1) I recognize I backtracked slightly on disliking this pattern.  I
do think it is safe, since a state change between validation and
saving there is just as likely as when done within the save method,
assuming there is no db synchronization.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to