と の 2 つのテーブルがRegion
ありDistrict
ます。テーブルregion_id
へforeign key
のも同様ですDistrict
( aregion
には 1 つまたは複数の がありますdistricts
)。そのため、 を選択するregion
と、その特定の に関連付けられlist
た のみを表示したいと考えています。私の正しいコードは、すべてとは無関係に表示されます:districts
region
districts
region
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
}
}