What is the best way of getting a map of all properties of a domain object, excluding the associations? In particular I need to exclude the hasMany
associations (collections.)
Right now I'm hardwiring the list of properties to exclude:
def p = someBook.properties
p = p.subMap(p.keySet() - ['authors', 'editors', 'formats'])
I did make sure that properties
returns a lazy collection, insofar as subMap() and keySet() are concerned, so that the excluded properties are not actually fetched from the DB.
But I'd rather not hardcode the list of associations.
Exclude all associations by discarding the key value pairs from properties
.
someBook.properties.findAll { !( it.key in someBook.hasMany?.keySet() ) }