Cascading
It is common to have nested objects. In the following we have a book inside of the sam object.
Sam := Person first: 'Sam' last: 'Hinton'.
catInTheHat := Book title: 'Cat in the Hat'.
sam addBook: catInTheHat.
Writing is said to cascade if by writing the outer object the inner object is also written. In GLORP writes are cascaded. So in the following both the Person object and the book object will be written to the database.
session inUnitOfWorkDo: [session register: sam]
In GLORP updates are also cascaded. If the method fooBar below modifies some instance variable of Sam, the modified instance variable will be updated in the database. It fooBar modifies an instance variable of an instance variable of Sam the database will be updated in the database. So when we make changes to object read from the database committing the changes would update the database regardless of where the object graph changes occur.
session inUnitOfWorkDo:
[sam := session readOneOf: Person where: [:each | each firstName = ‘Sam’].
sam fooBar.]
Deletes do not cascade. So in the code below, deleting sam does not delete the books that sam references. If you want those books to be deleted you need to delete them explicitly. If you set the book references in sam to nil and then delete sam, GLORP will make sure that book links no longer reference the sam row in the database.
session inUnitOfWorkDo:
[sam := session readOneOf: Person where: [:each | each firstName = ‘Sam’].
session delete: sam.]
Last modified date: 01/29/2015