protected function generateMorphableClasses(array &$metadata)
    {
        foreach ($metadata as $key => $entityMetadata) {
            foreach ($entityMetadata['relations'] as $relationKey => $relationMetadata) {
                // get morphable classes for morphTo relations
                if ($relationMetadata['type'] == 'morphTo') {
                    $metadata[$key]['relations'][$relationKey]['options']['morphableClasses']
                        = $this->getMorphableClasses($entityMetadata['class'], $relationMetadata['options']['morphName'], $metadata);
                }

                // get morphable classes for morphToMany relations
                if ($relationMetadata['type'] == 'morphToMany' && ! $relationMetadata['options']['inverse']) {
                    $metadata[$key]['relations'][$relationKey]['options']['morphableClasses']
                        = $this->getMorphableClasses($entityMetadata['class'], $relationMetadata['options']['morphName'], $metadata, true);
                }
            }
        }
    }