使用分页的能力是目标,但是我不确定如何使用它。这种关系是单向的 hasMany(见下文)。目前它在没有分页的情况下可以正常工作(请参阅屏幕截图),但是要使用分页,我必须更改控制器以使用 createCriteria。这就是我遇到困难的地方,因为这种关系很奇怪。
领域
Class Tag {
String Tag
User user
static hasMany = [events: Event]
}
控制器
def searchTags() {
println("TAG CONTROLLER - Params sent on click of tag are: "+params.selected)
def results = Tag.findByTagAndUser(params.selected, lookupPerson())
//resultTotal is for show for the time being
[query: params.selected, results: results, resultTotal: 0]
}
普惠制
<g:each in="${results.events}" status="i" var="t">
.... ommited as unnessary
</g:each>
//Not working yet due to confusing createCriteria issue
<div class="pagination">
<g:paginate total="${resultTotal}" />
</div>
我可以做一些指导,这是我到目前为止的想法,但我有点困惑:
def tagCriteria = Tag.createCriteria()
def result = tagCriteria.list (max: 50, offset: 10) {
eq("tag", params.selected)
and {
eq("user", lookupPerson())
}
//Not sure what to do at this point compared with the findByTagAndUser(params.selected, lookupPerson()).events events being the hasMany relationship seen in domain
events {
}
}