Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active May 24, 2020 10:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/026f189efa17391646d9 to your computer and use it in GitHub Desktop.
Save baybatu/026f189efa17391646d9 to your computer and use it in GitHub Desktop.
Getting mapping from domain class in Grails
class Person {
Long id
String name
static mapping = {
table name: 'PERSON'
id column: 'PRS_ID'
name column: 'PRS_NAME'
}
}
/*
* You can manipulate and collect mapping entries as you wish.
* Here, i reversed mapping entries of Person class.
* Output:
* ['PRS_ID': 'id', 'PRS_NAME': 'name']
*/
def collectedMap = new GrailsDomainBinder().getMapping(Person).columns.collectEntries { key, value ->
[value.columns.get(0).name, key]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment