protected function validateRelatedEntity(EntityInterface $relatedEntity, EntityInterface $entity, \Spot\Relation\RelationAbstract $relation)
{
$tainted = $relatedEntity->isNew() || $relatedEntity->isModified();
$errorsRelated = [];
if ($tainted && !$this->getMapper(get_class($relatedEntity))->validate($relatedEntity)) {
$errorsRelated = $relatedEntity->errors();
//Disable validation on foreign key field it will be filled up later on when the new entity is persisted
if (($relation instanceof Relation\HasMany || $relation instanceof Relation\HasOne) && $relatedEntity->isNew()) {
unset($errorsRelated[$relation->foreignKey()]);
}
$relatedEntity->errors($errorsRelated);
}
if ($relation instanceof Relation\BelongsTo && $entity->isNew()) {
$errors = $entity->errors();
unset($errors[$relation->localKey()]);
$entity->errors($errors);
}
return $errorsRelated;
}