groovy Grails- Criteria builders -Grails标准

b5lpy0ml  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(145)

场景如下:每个Process都有多个ProcessingSteps
我写的代码能够获取所有进程,而不需要对应于ProcessingSteps
我知道我漏掉了一个where子句,我想问一下我们在Grails中是如何做到这一点的。
我只想为每个Process获取相应的ProcessingStepUpdate
我有两个域类ProcessingStepProcessingStepUpdate

package a.b.c
public class ProcessingStep {
    Process process
}

public class ProcessingStepUpdate{
static belongsTo = [processingStep: ProcessingStep]
ProcessingStep processingStep
}

字符串
这是我写的剧本

Process.list(max:1).each {
    //List<ProcessingStep> test2= ProcessingStep.findAllByProcess(it)
    //println it
    def test3 = ProcessingStep.createCriteria().list() {
        eq("process",it)
    }
    println it

    it.list().each {
        //not telling it where to get the list from 
        ProcessingStep.list().each { pstep ->
            def test4 = ProcessingStepUpdate.createCriteria().list() {
                eq("processingStep",pstep)

                // Projections are aggregating, reporting, and
                // filtering functions that can be applied after
                // the query has finished.
                // A common use for projections is to summarize data
                // in a query
                /* projections{
                    groupProperty("processingStep")
                }*/
            }
            println pstep
            //List<ProcessingStepUpdate> test = ProcessingStepUpdate.findAllByProcessingStep(it)
            //List<ProcessingStepUpdate> test = ProcessingStepUpdate.findWhere()
            //println "it"
        }
    }
}


我一直在这个问题上停留在一天..新的OOPS世界!

smdnsysy

smdnsysy1#

我试着猜测这个任务只是为了保护孩子的孩子。那么它是这样的:

public class Process {
  static hasMany = [processingSteps: ProcessingStep]
}

public class ProcessingStep {
  static belongsTo = [process: Process]
  static hasMany = [updates: ProcessingStepUpdate]
}

public class ProcessingStepUpdate {
  static belongsTo = [processingStep: ProcessingStep]
}

Process.list().each{ process -> 
  process.processingSteps.each { step ->
    step.updates.each {
      println "Process: $process, Update: $it"
    }
  }
}

字符串
或甚至

def updates = Process.list()*.processingSteps.flatten()*.updates.flatten()
println updates.join('\n')


看一下Groovy Collections,特别是在“星号'*.'运算符”部分。

相关问题