2017-03-02 22 views
0

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クラスのもので、追加のフックが必要

+0

あなたのドメインモデルでは、buildingpartは建物の建物の部分でなければならないとは言いません。カスタム検証を追加してこれを確認することができます。ドロップダウンまでは、それが正しいことを確認するまでです。 –

+0

@James Kleeh:静的belongsTo = [building:Building]はそれを行いますが。 –

+0

いいえ、そうではありません。 BuildingpartのbelongsToとProjectのhasOneは異なるプロパティです –

答えて

0

デザインは、あなたの選択ボックスを言うとき、これはにいるので、私には意味がありません[OK]を探します私たちはここで私たちはそれが何であるか全く分かりません。あなたのプロジェクトクラスの注釈もそれと呼ばれます:

Bauteil buildingpart

は、あなたはhasManyのbuildingparts: Buildingpart]

あなたに注意を払う必要があるものがある持っているのprintlnで起こって、以下に示す結合:あなたは、プロジェクト

からのオブジェクトの建物高に多くの部分を照会

project.building.getCurrentPart(project.buildingpart)

+0

私はBauteilのbuildingpartをBuildingpartのbuildingpartに訂正しました。私はそれを忘れていました。 –