protected function parseRelation($name, Annotation $annotation, EntityDefinition &$entityMetadata)
    {
        // check if relation type is valid
        $this->validator->validateRelationType($annotation->type);

        // check if we need to add base namespace from configuration
        $annotation->relatedEntity = $annotation->relatedEntity
            ? $this->getRealEntity($annotation->relatedEntity, $entityMetadata['class'])
            : null;
        $annotation->throughEntity = $annotation->throughEntity
            ? $this->getRealEntity($annotation->throughEntity, $entityMetadata['class'])
            : null;

        // change morphedByMany to inverse morphToMany
        if ($annotation->type == 'morphedByMany') {
            $annotation->type = 'morphToMany';
            $annotation->inverse = true;
        }

        // create extra columns for belongsTo
        if ($annotation->type == 'belongsTo') {
            $this->generateBelongsToColumns($name, $annotation, $entityMetadata);
        }
        
        // create extra columns for morphTo
        if ($annotation->type == 'morphTo') {
            $this->generateMorphToColumns($name, $annotation, $entityMetadata);
        }

        $pivotTable = null;

        // create pivot table for belongsToMany
        if ($annotation->type == 'belongsToMany') {
            $pivotTable = $this->generateBelongsToManyPivotTable($name, $annotation, $entityMetadata);
        }

        // create pivot table for morphToMany
        if ($annotation->type == 'morphToMany') {
            $pivotTable = $this->generateMorphToManyPivotTable($name, $annotation, $entityMetadata);
        }

        // add relation
        return new RelationDefinition([
            'name' => $name,
            'type' => $annotation->type,
            'relatedEntity' => $annotation->relatedEntity,
            'pivotTable' => $pivotTable,
            'options' => $this->generateRelationOptionsArray($name, $annotation, $entityMetadata)
        ]);
    }