> The current situation is that the Model#create method "silently" fails
> if the validations fail. That is, there is no exception, and the
> return value is basically the same for success or failure; i.e. the
> model instance. What this means is that code that uses the return
> value is fooled into thinking the create() succeeded even though it
> failed. This leads to hard to find bugs. I know this from experience :-
> (
>
> The return value from the create can be checked to determine success
> or failure, but this is a pain and easy to forget to do.
>
> So my suggestion is this: create() should return nil on failure. This
> solves all the aforementioned problems, and seems like the obvious
> solution. Am I missing something?
>
> I could not find a ticket filed for this. If I missed it, let me know.
> Otherwise I will file one, possibly with the patch.

While I can understand your reason for this, the problem I'd have is
you'd have no way of finding out why the create failed.  The reason we
return the unsaved resource is because you can call
Resource#new_record? on it to see if it was persisted or not, and if
not you can introspect the resource to know the reasons why. This is
the convention we've established with other persistence methods in
DataMapper and it seems to be working quite well.

Dan
(dkubb)
--~--~---------~--~----~------------~-------~--~----~
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