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