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
, but addAll()
works with any Collection
.
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.
otherItems.each { foo.addToBars(it) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With