0
我有两个域:如何获取类的实例而不是其子类?
事件:
class Incident {
String title
String description
}
static mapping = {
tablePerHierarchy(false)
}
而且IncidentWithTimers延伸事件:
class IncidentWithTimers extends Incident {
int currentResponseTime
Date responseTimeEndDate
}
IncidentWithTimers是不是在数据库中实际的表,这是一个数据库视图。由于该领域是一个看法,我通过在beforeInsert
/Update
抛出异常禁用所有修改
def index() {
Incident curIncident = Incident.get(params.incident)
println(curIncident.getClass())// "class IncidentWithTimers"
}
:
现在,当我尝试从一个控制器获得一个事件实例,它在某种程度上返回IncidentWithTimers实例/ Delete
,在IncidentWithTimers类中。
当我尝试修改并保存curIncident时,它尝试访问beforeUpdate()
,并引发错误,而我从来不想首先更改IncidentWithTimers
。
我该怎么办?
'params.incident'中的事件ID是指'Incident'还是IncidentWithTimers'的实例? –
都不是。 params.incident从查询字符串中获取事件的值。 (所以url.com/?incident=1会返回1)。 – Ivar
我的意思是,按照你的例子,ID 1是事件或IncidentWithTimers的事件?另外,“IncidentWithTimers”被映射为来自“事件”映射到的同一个表的视图返回的ID是什么?是的,我暗示两者应共享相同的ID“名称空间”。 –