Based on all the feedback, it is clear that there is not much consensus
around my idea. Before I give up, I have another suggestion: we could add an
option to create() and save() to specify how validation failures should be
handled. Specifically:

:failure => :throw                   # throw exception on validation error
(save and create)
:failure => :return_nil             # return nil on validation error (only
for create)
:failure => :return_resource    # return resource instance on validation
error (only for create)
:failure => :nil                       # default behavior (save and create)

In addition, there could be a way to change the default behavior for save
and create through DM config options.

This could be through a plug-in or folded into the trunk.

Thoughts?

..tony..



On Mon, Dec 15, 2008 at 10:56 AM, Rupert Voelcker <[email protected]>wrote:

>
> > As I mentioned in an earlier post, my suggestion is that one uses
> create()
> > when all validations are expected to pass, and new/save in all other
> cases.
> >
> > Another way of putting this: create() is supposed to provide a quickie
> way
> > to create a saved model instance. If you are checking for errors, it's
> not
> > quickie :-)
>
> I must admit I find having the unsaved model returned very handy for
> debugging unexpected problems with ruby-debug as you actually have
> something you can look at to see why it's failed.
>
> If you feel strongly about this why not write a plugin for datamapper
> that exhibits this behavior (it would be pretty trivial to implement).
>  If you do this and it's heavily used then I'm sure you'll have more
> leverage in trying to add this behavior into datamapper itself -
> although I presume this would still be difficult as it'd be a fairly
> major change to the public api that could potentially break peoples
> code.
>
> My two-penneth
>
> Rupes
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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