2012-01-10 64 views
0

儿童的名单我都historystep的有两个领域类一个多对一显示与父ID

1)

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' 

    } 


} 
} 

而且

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

您是使用默认脚手架还是自己编写视图? – 2012-01-10 18:05:40

+0

由控制器通过grails自动生成的默认脚手架。 – element40 2012-01-10 18:09:32

+0

你真的应该遵循一般的java编码标准。下划线是来自不区分大小写的数据库(如Oracle)的传统约定。你真的不应该在Java/Groovy中使用它们......永远。好吧,常量可以有下划线,但无论如何。 http://www.oracle.com/technetwork/java/codeconvtoc-136057.html – dbrin 2012-01-11 06:20:53

回答

0

所有右对齐回答我的问题。在这里,我如何解决它。

1)
从OpfWF_Entry的列表视图中,我调用了historyStepInfo-Controller的搜索动作(搜索我自己添加的动作)。

2)hisotryStepInfo域内发现使用params.id所有匹配的行
在historyStepInfoController-我已经加入searchme动作 - (从opfEntry的列表视图)

DEF opfWF_HistoryStepsInfoInstanceList = OpfWF_HistoryStepsInfo.findAllByEntry_id(PARAMS传递.ID)

渲染(视图: '列表',型号:[opfWF_HistoryStepsInfoInstanceList:opfWF_HistoryStepsInfoInstanceList,opfWF_HistoryStepsInfoInstanceTotal:opfWF_HistoryStepsInfoInstanceList.count()])

3 )
添加HistoryStepsInfoInstanceList列表视图historyStepInfo“in”-varibale

在那里我得到所有与父母选择相关的孩子。

这项工作的一切。搜索,儿童列表等等。

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 2012-01-10 18:57:48

+0

你基本上有一个简单的一对多关系。如果我正确地理解了你,你需要一个显示与OpfWF_Entry关联的所有historySteps的表格。你真的必须添加这个视图,没有简单的“脚手架”方式来做到这一点。 – ibaralf 2012-01-10 23:58:09

+0

谢谢ibaralf。你的答案给了我方向。 – element40 2012-01-11 14:51:24