Last active
May 24, 2020 10:06
-
-
Save baybatu/026f189efa17391646d9 to your computer and use it in GitHub Desktop.
Getting mapping from domain class in Grails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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