« Return to Thread: "findOrCreateBy"

Re: "findOrCreateBy"

by Moe-25 :: Rate this Message:

Reply to Author | View in Thread

On Sun, Jul 5, 2009 at 12:39 AM, Jeff Brown <jeff@...> wrote:
On Sat, Jul 4, 2009 at 12:09 PM, Moe<mohamed5432154321@...> wrote:
> Thats a good idea, the GORM labs and when it comes to the name of the method
> I think it sounds easy enough.
> On whether or not its necessary (although Robert don't want any input :P) I
> do think it would be good standard method for grails gorm, I am sure most
> folks have this code somewhere in their apps and should therefore be a
> standard one.
> def item = Item.findByName('someName') ?: new Item(name:'default',
> property:'something').save(flush:true)
>
> for example wouldn't work. It will return either true or false.

I don't think that will return a boolean.  I think that will return
null or an Item.  It will return an Item if findByName returns an item
or if save() is successful, otherwise return null.  Right?

 You are absolutely right! Poor testing from my side :O .. I need to pay more attention!

Moe

 « Return to Thread: "findOrCreateBy"