I have a domain object on which I want to store several things that exist only at runtime. I looked at the documentation and found the transients keyword, which, at first glance, was what I was looking for. This 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 the groovy class, which is not a domain object, but a placeholder for some properties.
So far, everything is in order, and my contact table does not have a pal field, as expected. In my ContactController request for a bunch of contacts c , then find their Seeker pals (details on how to remove them) and set a new object for the pal field.
c.pal = new Seeker(); c.pal.name = otherObject.name render c as JSON
All this works fine, except that the pal object is missing from the returned JSON.
Is this a legitimate use of transients? The docs mention that they are convenient for function-based getters and seters, but in my case I want an actual object. Should I write a getPal () and setPal () method for my object?
thanks
Simon source share