0
我已經建立了這樣的條件:Grails的 - 獲得查詢柱接合表
def e = Equipment.createCriteria()
def equipmentInstanceList = e.list {
createAlias "rentals", "r", org.hibernate.sql.JoinType.LEFT_OUTER_JOIN
projections {
property('name')
property('r.status')
property('r.dateRented')
property('r.dateReturned')
}
}
我的想法,它會返回2維列表。如提到here。據我所知,第一個列表是所選項目的列表,第二個列表是項目列表的列表。我的問題是
如何獲得所有選定的項目?示例:
def list = equipmentInstanceList.[all] //supposed to get all the selected items
def a = equipmentInstanceList[1] //will only get the 1st item in 1st list
如何訪問第二個列表中的特定列?例如:
def a = equipmentInstanceList[1].status //supposed to get the status column in 2nd list
編輯:
該查詢有相同的結果與上述的標準。
def equipmentForRent = Equipment.executeQuery("SELECT e.name, r.status, r.dateRented, r.dateReturned FROM ers.Equipment e LEFT JOIN e.rentals r")
我仍然試圖獲取equipmentForRent
中的列。我到目前爲止所嘗試的。
each.equipmentForRent { e -> println e.dateReturned }
仍然得到這個錯誤:
Exception evaluating property 'dateRented' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: dateRented for class: java.lang.String
爲什麼從該查詢不同:
def rentalTest = Rental.executeQuery("FROM Rental")
println rentalTest.status //no error, returns the status column from rental
有人嗎?
您建議的解決方案中的地圖的關鍵將作爲真正的專欄嗎? – newbie
對不起我的無意義的問題。您的幫助非常感謝查詢中的「新地圖」方法解決了我的問題 – newbie
沒有問題我推測您的第二條評論意味着您瞭解它。 – Vahid