Cleaned up tests for multiple databases.
Fixed transaction handling for a number of operations on related objects.

Thanks Anssi and Aymeric for the reviews. Refs #21174.
Merge pull request #2489 from loic/related_transactions

Fixed transaction handling for a number of operations on related objects.