In java, if I have a list, I can use addAll(otherList); to add all the elements from one list to another.
What is the equivalent in grails? I have a Domain object with a hasMany relationship. To add to it, I would use something like
Object.addToMyList(someitem);
and it seems like
Object.addAllToMyList(otherList)
does not exist.
What is the equivalent in grails?
To clarify – by default the collection is a
Set, butaddAll()works with anyCollection.You can call
addAll()and it’ll work fine, although the back-references won’t be set if it’s bidirectional. This doesn’t affect persistence, just the current in-memory state.There’s nothing built into GORM for this, so I suppose the “right” way is a loop, e.g.