Fixed undefined modelClass when using polymorphic relations

When using polymorphic relations the through model has no relation to another model, hence the modelTo variable might be undefined or null.