I am following this link to bring some positive changes regarding performance in my app.
I have following two classes
class Topic {
String title
String body
String type
User user
static mapping = {
body type:"text"
}
}
and
class Follower {
Topic topic
User user
static constraints = {
}
}
Keeping above two classes in mind, is it possible to write equivalent criteria for following query?
SELECT title,follower.user_ID,topic.id FROM TOPIC
left outer join follower on topic.id = follower.topic_id
where follower.user_id = 1 or follower.user_id is null;
I came up with following criteria which fails because there is neither reference of follower
in topic
nor I could find a way to swing this criteria to right join because there is no such criteria specification
def recentQuestions = Topic.createCriteria().list([sort:'lastUpdated',order:'desc',max:5]){
createAlias "follower", "f" , CriteriaSpecification.LEFT_JOIN
or{
eq('f.user',u)
isNull('f.user')
}
eq('type','FORUM',[ignoreCase: true])
}