0
在下面的代碼如何刪除與作者assoicated所有的舊商店記錄,並插入一個新的Grails的Groovy中刪除舊記錄
域類
class Store {
Date dateCreated
Date lastUpdated
static belongsTo = [author: Author]
static constraints = {
}
}
域控制器
def update() {
if (!requestIsJson()) {
respondNotAcceptable()
return
}
def bookInstance = book.get(params.id)
if (!bookInstance) {
respondNotFound params.id
return
}
if (params.version != null) {
if (bookInstance.version > params.long('version')) {
respondConflict(bookInstance)
return
}
}
def stores = bookInstance.stores
//bookInstance.delete(flush:true);
//stores.delete(flush:true);
bookInstance.properties = request.GSON
if (bookInstance.save(flush: true)) {
respondUpdated bookInstance
} else {
respondUnprocessableEntity bookInstance
}
}
你可以添加'Author'類的源代碼嗎?沒有它就無法給予解決方案。 – rxn1d