I have three class interlinked with each other.
Initially I build query without pagination and all search results were fine. But now I need pagination and don't want to disturb my initial query pattern. Is there any way I could get distinct results.
Class Department{
int id;
String name;
static hasMany = [courses:Courses]
}
Class Courses{
String courseName;
String courseCode;
static hasMany = [student:Student]
static belongsTo = [department:Department]
}
Class Student{
String studentName;
String address;
static belongsTo = [courses:Courses]
}
//controller
def list = Department.createCriteria.listDistinct{
if(params.id){
and{eq{"id",params.id}}
}
and{
courses{
if(params.courseName){
and{eq("courseName",params.courseName)}
}
}
and{
student{
if(params.studentName){
and{eq("studentName",params.studentName)}
}
}
}
}
}
I could not gave you the actual tables and domains, but the relation is pretty much the same as above. It worked really fine for dintinct results but couldnot paginate. I have tried a number of solution but it returns error. I have not recorded any errors till now. I have came to know listDistinct can not be used for pagination parameters. and list doesnot provide distinct parameters.
I tried projection but couldnot retrieve all the attributes as before. Is there any solutions to it. As I need to search from all possible attributes with all the realtion from any of the three tables. Do I need to switch all my query to another method?