(#22363) Add relationship test

This also fixes problems with relationship evaluation.