Join fetching related objects that use inheritance causes wrong SQL

Adds tests to verify my case to be correctly working