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

前端 未结 4 611
耶瑟儿~
耶瑟儿~ 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:52

    For #1 you can clear the collection (it's a Set by default):

    activePerson.locations.clear()
    

    For #2 use addToLocations:

    activePerson.addToLocations(location)
    

    and when you save the person the location<->person relationship will be updated.

提交回复
热议问题