2

场景是这样的:每个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 世界的新手!

4

1 回答 1

0

我会尝试猜测该任务只是迭代孩子的孩子。然后是这样的:

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,尤其是“star-dot '*”。运营商”部分。

于 2012-08-02T10:05:19.390 回答