我有下一个方案:
class UserProfile {
String title
String firstName
String lastName
static belongsTo = [user:User]
static constraints = {
user nullable:true , unique:true
title nullable:true, blank:true
firstName blank:false
lastName nullable:true, blank:true
}
}
class User {
String username
String password
boolean enabled
String email
static constraints = {
username size:6..40, blank:false, nullable: false, unique: true
email email:true, size:6..40, blank:false, nullable: false, unique: true
password size:5..64, password:true, blank:false, nullable: false
}
String toString(){username}
}
我需要UserProfile
有用户的电子邮件订购的列表!
我尝试:
UserProfile.createCriteria().listDistinct({
if(params.orderBy){
if(params.orderBy=="email"){
//the exception says that the element has no such property to both cases
order("user.email", ascDesc)
//order("email", ascDesc)
}else{
order("${params.orderBy}", ascDesc)
}
}
})
所以当我想通过电子邮件订购时,异常表明该元素对这两种情况都没有这样的属性。注意:ascDesc
是一个变量String
,它可以是asc
或desc