This test is comparable to the second test `test_polymorphic_where_with_relation` in #10366