Restrict the scope of data when using withCriteria
I currently have the following 3 domain classes :
User.groovy
class User {
...
static hasMany = [
...
]
static belongsTo = [
course : Course,
university : University
]
}
Course.groovy
class Course {
String title
static hasMany = [
universities : University,
users : User
]
static belongsTo = University
}
University.groovy
class University {
String name
static hasMany = [
courses : Course,
users : User
]
}
I gather all of the courses for a university with the following code :
def courses = Course.withCriteria {
universities {
eq('id', Long.parseLong(params.universityId))
}
}
render courses as JSON
With an example response like so :
[{
"class":"classifieds.Course",
"id":1,
"title":"Computer Science",
"universities":
[{"class":"University",
"id":1}],
"users":
[{"class":"User"
,"id":1}]
}]
My issue is that I want to restrict the scope of the response to not
include the users or universitiesthat are currently being returned, I only
what a list of courses to be returned in the JSON. How to I restrict this?
No comments:
Post a Comment