GORMの仕組みを理解しようとしています。 ビルディングとビルディングパート(素晴らしい建物のエリア)を持つプロジェクト用のデータベースを構築することは、私が望むようには機能しません。私が欲しいのは、各プロジェクトには1つの建物とその建物の建物部分があります。その方法は、すべてのbuildingpartのために私にdropdownmenuを与え、selectetビルからのものだけでなくGORMの基本的な問題点
class Project {
String name
static hasOne = [building: Building]
Buildingpart buildingpart
String toString(){
return name
}
}
class Building {
String name
static hasMany = [projects: Project, buildingparts: Buildingpart]
String toString(){
return name
}
}
class Buildingpart {
String buildingpart
static belongsTo = [building: Building]
String toString(){
return buildingpart
}
}
それをやって:
私はそのようにしようとしました。 私は何か提案があればうれしいです。おそらく、その後Buildingpart getCurrentPart(Buildingpart buildingPart) {
return this.buildingparts.find{buildingPart}
}
Project project = project.get(id)
println "project building = ${project.building}"
println "project buildingparts = ${project.building.buildingparts}"
println "project currentpart = ${project.building.getCurrentPart(project.buildingpart)}"
ようBuilding
クラスのもので、追加のフックが必要
あなたのドメインモデルでは、buildingpartは建物の建物の部分でなければならないとは言いません。カスタム検証を追加してこれを確認することができます。ドロップダウンまでは、それが正しいことを確認するまでです。 –
@James Kleeh:静的belongsTo = [building:Building]はそれを行いますが。 –
いいえ、そうではありません。 BuildingpartのbelongsToとProjectのhasOneは異なるプロパティです –