2012-05-25 51 views
0

我正在使用来自开源应用程序(OSTicket)的现有数据库。有两个表(OstStaff和OstTicket,其中员工有许多门票)。但是,最大的问题在于,如果票证尚未分配给OstStaff,OSTicket会将默认值为0分配给OstTicket.staff_id。Grails - 使用零索引导致GORM运行时异常的MySQL查询结果

当你搜索票和格姆认为有与指数等于0员工我甚至不能检查空的问题出现了,只是不停收到此错误:

No row with the given identifier exists: [com.facilities.model.OstFacStaff#0]. 
Stacktrace follows: 
Message: No row with the given identifier exists: [com.facilities.model.OstFacStaff#0] 

任何建议我如何解决这个问题?谢谢。

回答

0

由刚开始的ID,而不是记录,然后除去零索引解决了这个。

def ticketCriteria = OstFacTicket.createCriteria() 
def staffIdsWithTickets = ticketCriteria.list { 
    projections { 
     distinct("staff.id") // **INSTEAD of returning staff, get the id** 
    } 
    between("created", start, end) 
} 

def zeroIndex = staffIdsWithTickets.indexOf(0) 
if (zeroIndex >= 0) { 
    staffIdsWithTickets.remove(zeroIndex) 
}