繁体   English   中英

在Grails GORM中搜索域对象的子级

[英]Searching through children of an domain object in Grails GORM

如何在Groovy / Gorm中正确编写此代码?

我有一个包含许多ContentPageComponent域类。 我想看看特定的PageComponent是否包含带有特定Content

我以为我可以说:

def pageComponent = PageComponent.get(1);

if (pageComponent.contents.findByKey("textnode") {
  // update
} else {
  // insert
}

目前,我正在使用它。 不太优雅...

def pageComponent = PageComponent.get(1);

def content = Content.withCriteria {
    eq "pageComponent.id", pageComponent.id
    eq "key", "textnode"
}

您还可以使用动态查找器:

Content.findByPageComponentAndKey(pageComponent, "textnode")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM