情景是这样的:
每个Process
都有多个ProcessingSteps
我编写的代码能够在不与ProcessingSteps
对应的情况下获取所有进程。
我知道我错过了where子句,我想问一下我们如何在Grails中这样做。
我只想获取相应Process
ProcessingStepUpdate
我有两个域类ProcessingStep
和ProcessingStepUpdate
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世界的新手!
答案 0 :(得分: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,特别是“星点”*。运营商“部分。