2012-05-25 42 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) 
} 
相關問題