假设我有以下模型:
class Product {
String name
String price
String currency
static constraints = {
currency inList: ['USD', 'EUR']
}
现在我们有一个新要求,必须从服务中提取inList约束:currency
class CurrencyService {
def getAvailableCurrencies = {
...
}
}
我该如何进行这项工作?我试过了:
class Product {
def currencyService
...
static constraints = {
currency inList: currencyService.getAvailableCurrencies()
}
}
但我无法在上下文中访问currencyService实例。static constraints我也尝试过使用static currencyService,但这同样不起作用。有任何想法吗?