You are going to have to write extra code no matter what you do (for
instance, to catch an exception if you want it raised, or to check if
it returns nil). Rather than just doing this:

if Foo.create()
#....
end

You can do this if you really want to check for it in one line

if Foo.create().new_record?
 #....
end

new_record? is only true if the model has not been saved to the
database yet.

On Dec 13, 7:37 pm, "Tony Mann" <[email protected]> wrote:
> Dan,
>
> If a coder has reason to believe that saving a model will fail, then they
> could use new() and then save(). Thus create() would be reserved for those
> times when persistence failure is not part of the normal workflow.
>
> In its current form, create() does not provide a meaningful shortcut over
> new and then save, since the return value has to be manually checked. If
> create() returned nil on failure, then subsequent calls that depend on the
> return value would inevitably fail.
>
> That is, this is good:
>
>   foo = Foo.new
>
>   if foo.save
>     ...
>   else
>   end
>
> And this is good:
>
>   bar.foo = Foo.create(...)
>   bar.do_something
>
> But this is not good:
>
>   bar.foo = Foo.create()
>
>   if bar.foo.new_record?
>     ...
>   else
>     ...
>   end
>
> ..tony..

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