I have the following domain name that I used on grails version 2.5.5
class OrderBook {
int orderNumber
String mutationCode
Date mutationDate
User orderUser
OrderStatus status
OrderVendor vendor
String catalogueNumber
String orderDescription// (catalogue name) auto-completion from a vendor
Float pricePerUnit
Integer numberOfUnit
float vat
String orderUnit
Float shipHandleCost
Budget budget
boolean reception
String purchaseOrder
String comment
static constraints = {
orderNumber blank: false, unique: false, display:false
mutationCode blank: false, inList: ["c", "u", "d"], display:false //c: created, u:updated, d:deleted
mutationDate blank: false, display: false
orderUser blank: false, unique: false
status blank: false, unique: false
vendor blank: false, unique: false
catalogueNumber blank: false, unique: false
orderDescription blank: false, unique: false
pricePerUnit blank: false, unique: false
vat blank: false, unique: false
orderUnit blank: true, nullable: true
shipHandleCost blank: false, unique: false
budget blank: false, unique: false
purchaseOrder blank: false, unique: false
comment blank: true, nullable: true, type: 'text'
}
}
I wrote the following SQL request that work fine using executeQuery:
def orderBookLastList = be.vib.emone.OrderBook.executeQuery('''from OrderBook o where o.mutationDate in (select max(mutationDate) from OrderBook b where o.orderNumber=b.orderNumber) AND NOT o.mutationCode=:mutationDelete order by id''', [mutationDelete:'d'], [max: params.max, offset: params.offset])
I would like to write it in GORM style but I couldn't figure how to handle the subquery. I tried to use the WHERE but none of my trials worked.
Any tips will be welcome