I was under the wrong impression of saving enum type as ordinal values after completion of the issue https://jira.grails.org/browse/GPMONGODB-232 that we can now save enum with the custom id.
For example:
This won't save field type with values either 2 or 3.
package test
class User {
static mapping = {
//type enumType: "ordinal"
}
UserType type
String name
}
enum UserType {
A(2),
B(3),
int getId() {
this.id
}
final int id
UserType(int id) {
this.id = id
}
}
How can we save enum with custom ids (as shown above) in a grails app with mongodb plugin installed?
Answering my own question in case anyone need this feature. Now mongodb also supports saving enum with custom id as explained in the question.
The changes required are already merged by pull request https://github.com/grails/grails-data-mapping/pull/41 and they just have to release a new version of mongodb or GORM.