I'm reading an introductory book to Grails and I'm curious how this works.
I can understand a cascading delete, an example used was a list of songs belongsTo an Album, so if you delete the Album, the songs are deleted. However it then mentions cascading saves and edits, so if a saving action on an album cascades as well.
What does this mean specifically? If I changed the album.title and saved it, what sort of effect does a 'cascading save' here have? I fail to see anything impactful coming from this. Does it just mean it updates the name of the owning album of all those songs? If so... is that actually how it's supposed to work? I thought there would just be some sort of link or reference between an Album and owned Song object, not that a 'Song' object actually kept track of the name of it's owning Album with it's own piece of data.
Cascade saves in Grails usually applies to parent/child relationships. For example, given the following domains:
class User {
static hasMany = [addresses: Address]
}
class Address {
static belongsTo = [user: User]
}
And then the following code:
def user = new User()
def address = new Address()
user.addToAddresses(address)
user.save()
When the user is saved, cascading will also save the Address. The following would also cascade:
def user = User.get(1)
user.address.street = "123 st"
user.save()
Cascade would save the update to the address. In both of these situations, any errors would be collected in the User domain. So if the update to the Address.street failed, you would see those in user.errors
.