Handle STI in query generation