« Return to Thread: "findOrCreateBy"

Re: "findOrCreateBy"

by nycsailor :: Rate this Message:

Reply to Author | View in Thread

Do we need a new method for this or is this too much.  Seems like not
that much to me.

def item = Item.findByName('someName') ?: new Item()

Certainly, this would be more flexible.

def item = Item.findByName('someName') ?: new Item(name:'default', property:'something')

On Fri, 2009-07-03 at 15:41 -0400, Robert Fischer wrote:

> I'm adding "findOrCreateBy" in GORM Labs (does a find, and failing that, instantiates a new one).
> Anyone have a nicer nomenclature for that?
>
> ~~ Robert Fischer, Smokejumper IT Consulting.
> Enfranchised Mind Blog http://EnfranchisedMind.com/blog
>
> Check out my book, "Grails Persistence with GORM and GSQL"!
> http://www.smokejumperit.com/redirect.html
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: "findOrCreateBy"