Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails - how to pass Domain Objects and use services
    text
    copied!<p>I'm writing a service that shouldn't have to save anything. It gets some values. Looks up a few things in the database, and then coughs back a response. Is there anything I should do to make the service faster/less overhead? Also whats the best way to pass it something. I usually pass the id and get it again; is that good/bad/dumb?</p> <p>example</p> <pre><code>class DoStuffController { def ExampleProcessingService def yesDoIt = { def lookup = "findme" def theObject = ExampleThing.findByLookie(lookup) def lolMap = ExampleProcessingService.doYourThing(theObject.id) if(lolMap["successBool"]){ theObject.imaString = "Stuff" theObject.save() } [] } } </code></pre> <p>service</p> <pre><code>class ExampleProcessingService{ static transactional = true //???????? false? not-a? def doYourThing = {theID -&gt; def returnMap = [:] def myInstance = ExampleThing.get(theID) if(myInstance.something)returnMap.put "successBool", true else returnMap.put "successBool", false return returnMap } } </code></pre> <p>domain object</p> <pre><code>class ExampleThing { String imaString String lookie static constraints = { imaString(nullable:true) } def getSomething() { return true } } </code></pre> <p>bootstrap</p> <pre><code>import learngrails.* class BootStrap { def init = { servletContext -&gt; def newThing = new ExampleThing(lookie:"findme") newThing.save() } def destroy = { } } </code></pre> <p>Is the an advantage, disadvantage or standard to passing ID and doing get vs. passing the object? Does this change given my case of not going to save anything in the service? Is there something I'm doing glaringly wrong? Do you have a better suggestion for the title? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload