How do I clear and replace a collection in a one-to-many relationship in Grails/Groovy

前端 未结 4 617
耶瑟儿~
耶瑟儿~ 2021-02-14 06:13

This question is in two parts, first part is about clearing a list and second part is about assigning an owner to an object.

I have a one-to-many relationship between tw

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 06:45

    Here's what works for me:

    activePerson.locations.clear()
    activePerson.properties = params
    
    ...
    
    activePerson.save()
    

    This clears the set of locations, then adds back just the ones currently selected in params.

提交回复
热议问题