There are a few ENUM examples of Grails (here also in SO), but I cannot get the desired results.
Solutions include 1) Having ENUM in a separate class under src / groovy Domain Class
class Offer { PaymentMethod acceptedPaymentMethod .. }
src / groovy PaymentMethod
public enum PaymentMethod { BYBANKTRANSFERINADVANCE('BANKADVANCE'), BYINVOICE('ByInvoice'), CASH('Cash'), CHECKINADVANCE('CheckInAdvance'), PAYPAL('PayPal'), String id PaymentMethod(String id) { this.id = id } }
In this case, the Enum class is not recognized at all in the domain class that throws an error. It looks like this was used to work with Grails prior to version 2.
Am I missing something? How to use an external ENUM class in a domain in Grails?
2) Put ENUM in the domain class.
In this case, grails does not complain at compile time, but scaffolds do not contain any ENUM value information (this is similar to the acceptPaymentMethod property, which is not included in the forest creation process at all) Example:
class Offer { PaymentMethod acceptedPaymentMethod .. enum PaymentMethod { BYBANKTRANSFERINADVANCE('BANKADVANCE'), BYINVOICE('ByInvoice'), CASH('Cash'), CHECKINADVANCE('CheckInAdvance'), PAYPAL('PayPal'), String id PaymentMethod(String id) { this.id = id } } }
Checking the structure of the database table, the field is not ENUM, but simply VarChar:
| accepted_payment_method | varchar(255) | YES | | NULL | |
Is there any support for ENUM on Grails Gorm in general?