How can I join a table with criteria in grails if I don't have field references in the domain class

I have two classes in the domain model:

class Project {
   String name
   Integer fund
}

class Task {
   String name
   Integer weight
   Project project
}

How can I get a project with Task.name = "something"?

If I need a task with Project.name = "something", I can do it using the createAlias ​​criteria, but how can I join Task in

c = Project.createCriteria()
   criteriaRes = c.list {
}
+4
source share
2 answers

, , SQL, , , , HQL, SQL, NoSQL, HQL - , GORM.

, HQL, , ,

def projects = Task.executeQuery(
   'select t.project from Task t where t.name=:taskName',
   [taskName: 'something'])

def projects = Task.createCriteria().list {
   eq 'name', 'something'
   projections {
      property 'project'
   }
}
+4

, , ( ) , :

class Project {
   String name
   Integer fund
   static hasMany = [tasks: Task]
}

class Task {
   String name
   Integer weight
   static belongsTo = [project: Project]
}
0

All Articles