2012-01-10 17 views
0

に関連した子のリストを表示多対1)私は2つのドメインクラス</p> <p>1を持つ親ID

package opfwflowmonitor 
import java.io.Serializable; 
class OpfWF_Entry implements Serializable{ 

String name 
Date create_date 
static hasOne=[siteName:OpfWF_SiteName, currentStepStatus:OpfWF_CurrentStepStatus,currentStepName:OpfWF_CurrentStepName] 
static hasMany = [historySteps:OpfWF_HistoryStepsInfo] 

static mapping = { 

      table name: "OS_WFENTRY", schema: "GSI" 
      version false 
      cache true 
      historySteps cache:true 
      sort id:"desc" 
      columns{ 
        name column:'NAME' 
        create_date column:'CREATE_DATE' 

    } 


} 
} 

そして

私はすべてのhistorystepのリストを表示するにはどうすればよい
package opfwflowmonitor 
import java.util.Date; 
class OpfWF_HistoryStepsInfo { 

Long entry_id 
Long action_id 
Long step_id 
Date start_date 
Date finish_date 
String status 

static belongsTo = [historyEntry: OpfWF_Entry] 

static mapping = { 
    table name: "OS_HISTORYSTEP", schema: "GSI" 
    version false 
    cache true 
    historyEntry cache: true 
    sort id:"desc" 
    id generators: 'assigned' 
    columns{ 
     id column:'ID' 
     action_id column:'ACTION_ID' 
     step_id column:'STEP_ID' 
     start_date column:'START_DATE' 
     finish_date column:'FINISH_DATE' 
     status column:'STATUS' 
    // ENTRY_ID column:'ENTRY_ID' 

     } 
    historyEntry column:'entry_id' 
    historyEntry insertable:false 
    historyEntry updateable:false 
} 

String toString() { "$id" } 
} 

私はOpfWF_Entryを選択するとすべてのプロパティ?

ユーザーがOpfWF_Entryテーブルのレコードのリストをクリックしたときに、履歴テーブルのすべてのプロパティを持つ子リストテーブルを取得する方法。

+0

デフォルトの足場を使用していますか、独自のビューを作成していますか? –

+0

デフォルトのスキャフォールディングは、コントローラでgrailsによって自動的に生成されます。 – element40

+0

あなたは本当に一般的なJavaコーディング標準に従うべきです。アンダースコアは、Oracleなどの大文字と小文字を区別しないデータベースの従来の表記規則です。あなたは本当にJava/Groovyでそれらを使用しないでください...これまで。まあOKの定数は下線を持つことができますが、何でも構いません。 http://www.oracle.com/technetwork/java/codeconvtoc-136057.html – dbrin

答えて

0

すべて右 - 私の質問に答えます。ここで私はそれをどのように解決しました。

1)
OpfWF_Entryのリストビューから、私はhistoryStepInfo-Controllerのsearchmeアクション(search me action added myself)を呼び出しました。 params.idを使用して、一致するすべての行に対してhisotryStepInfoドメインの内部に見つけ

2)historyStepInfoController-において
I追加したsearchmeのアクション(Action)は、(opfEntryのリストビュー)

DEF opfWF_HistoryStepsInfoInstanceList = OpfWF_HistoryStepsInfo.findAllByEntry_id(paramsはから渡されました)

3([opfWF_HistoryStepsInfoInstanceList:::opfWF_HistoryStepsInfoInstanceList、opfWF_HistoryStepsInfoInstanceTotal opfWF_HistoryStepsInfoInstanceList.count(:モデル、 'リスト' ビュー)] .ID)

レンダリング)
"in" -varibaleのhistoryStepInfoビューを表示するHistoryStepsInfoInstanceListを追加しました

そして、そこには親の選択に関連するすべての子があります。

これはすべての作業です。検索、子供のリストと何でも。

0

質問が正しく理解されているかどうかは完全にはわかりません。 OpfWF_Entryオブジェクトがあるときにプロパティを表示する必要がありますが、その場合はアクセスできません。必要なプロパティを公開するメソッドを作成できます。

コントローラー:

def showAllHistorySteps = { 
    def opfwfEntry = OpfWF_Entry.findById(params.id) 
    def historySteps = opfwfEntry.historySteps 
    historySteps.each { 
     println "Step: ${it.toString()}" 
    } 
    return [historySteps:historySteps] 
} 

ドメイン:

class OpfWF_HistoryStepsInfo { 
    def getAllProperties() { 
     // code to return a list of properties you want 
    } 
} 

ビュー:

< g:each in="historySteps" > <br/> 
    < g:set var="listOfProps" value="${it.getAllProperties()"/> <br/> 
    // do what you want with listOfProps <br/> 
< /g:each> <br/> 
+0

以下の回答を投稿しました。選択したwf_entryテーブルレコードに関連するすべてのhistorystep(historystepinfoドメインのすべてのプロパティを含む)を表示する履歴ステップのリストビューが必要です。 – element40

+0

基本的には、単純な一対多の関係です。私があなたを正しく理解していれば、OpfWF_Entryに関連付けられているすべてのhistoryStepsを示すテーブルが表示されます。実際にビューにこれを追加する必要があります。これを行うための簡単な「足場」の方法はありません。 – ibaralf

+0

ibaralfありがとうございます。あなたの答えは私に方向性を与えています。 – element40

関連する問題