开发者

grails composite ID does not work

I have the following domain class:

class AccountSupplier implem开发者_Python百科ents Serializable {

    static mapping = {
       table 'MY_TABLE'
       version false

       accountReference /*indexColumn: 'ACNTID', */ column:'REFACNTID'
       supplierReference /* indexColumn:'SUPID' ,*/ column:'REFSUPID'

       id composite:['accountReference', 'supplierReference']
    }

   Account accountReference
   Supplier supplierReference
}

everything works fine with this except the ID handling. When I try to get the ID of an AccountSupplier Object, i dont get anything. The effect is that i am not able to delete or edit something. Only listing does work (without ID)

how can i handle the ID for getting, deleting ...

thanks.


There is no actual ID. That's not really how composite ID's work. You'll need to provide a method on your class to allow for deleting (as well as other things)

static boolean remove(Account accountReference, Supplier supplierReference, boolean flush = false) {
  AccountSupplier instance = AccountSupplier.findByAccountAndSupplier(accountReference, supplierReference)
  instance ? instance.delete(flush: flush) : false
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜