Fixes case when an entity has a relationship with a class with joined inheritance