0

次のコードでは、著者に関連付けられた古い店舗レコードをすべて削除し、新しいレコードを挿入する方法を教えてください。

ドメインクラス

 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
    }
}
4

1 に答える 1