TestUtils: add helper function to create a subquery that inserts a relation

And use it in at least one place.