我有两张桌子:Region和District。入表region_id也是如此(一个有一个或多个)。因此,当我在我的上选择 a 时,我只想显示与该特定. 我的正确代码显示所有独立于:foreign keyDistrictregiondistrictsregionlistdistrictsregiondistrictsregion
def list = {
params.max = Math.min(params.max? params.int('max') : 20, 100)
[districtInstanceList : District.list(params),
districtInstanceTotal: District.count()]
}
有人知道如何仅根据外键约束显示吗?我知道我可以SQL在我的闭包中写一个查询list,但我想 grails 可能有办法做到这一点。我的数据库是MySQL,grails版本是2.0.1。我的District域名是:
class District {
def scaffold = true
String name
String description
String logo
String homepage
// defines the 1:n constrain with the Region table
static belongsTo = [region : Region]
// defines the 1: constraint with the Stream table
static hasMany = [streams : Stream]
static constraints ={
name(blank:false, minSize:6, maxSize:30)
description(blank: false, maxSize:100)
}
public String toString(){
name
}
}