Use an relation to build up the query from the common parts