« Return to Thread: "findOrCreateBy"

Re: "findOrCreateBy"

by Moe-25 :: Rate this Message:

Reply to Author | View in Thread

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 hope you will provide two maps, one to find by, and one with the "extra" properties to create by and the flush option :)

Moe

 « Return to Thread: "findOrCreateBy"