gpt4 book ai didi

grails - Grails-条件构建器-createCriteria

转载 作者:行者123 更新时间:2023-12-02 14:12:59 25 4
gpt4 key购买 nike

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

最佳答案

我将尝试猜测,该任务仅是迭代 child 的 child 。然后是这样的:

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,尤其是在“星点'*'处。运算符”部分。

关于grails - Grails-条件构建器-createCriteria,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com