I have a domain object on which I want to store a few things which only exist at runtime. I looked at the documentation and found the transients
keyword, which, on the face of it was what I was looking for. Here is what my domain object looks like...
class Contact {
def Seeker
def beforeInsert()
{
initiatedDate = new Date()
}
Date initiatedDate
Date acceptedDate
static transients = ['pal']
Seeker pal
}
where Seeker
is a groovy class which is not a domain object, but a placeholder for some properties.
So far all is fine and my Contact table does not have a pal
field as expected. In my ContactController
I query for a bunch of contacts, c
, then look up their Seeker
pals (details of how withheld) and set the pal
field to a new object.
c.pal = new Seeker();
c.pal.name = otherObject.name
render c as JSON
This all seems to work fine except that the pal object is missing from the JSON returned.
Is this a valid use of transients? The docs mention that they are handy for function-based getters and setters, but in my case I want an actual object. Should I be writing a getPal() and setPal() method on my object?
Thanks