Adds a new relation class to entity descriptor

@param string $name
@param string $class

@throws \Slick\Orm\Exception\InvalidArgumentException if class does not
exists or it does not implement the Slick\Orm\RelationInterface
interface
495227
public static function addRelationClass($name, $class)
    {
        $interface = 'Slick\Orm\RelationInterface';
        if (!class_exists($class)) {
            throw new InvalidArgumentException(
                "{$class} class does not exists"
            );
        }

        $rflClass = new ReflectionClass($class);
        if (!$rflClass->implementsInterface($interface)) {
            throw new InvalidArgumentException(
                "{$class} class does not implement '{$interface}' interface"
            );
        }

        static::$_annotations[$name] = $class;
    }
1339506
public function addRelation(TableRelation $relation, string $name = null)
    {
        $name = $name ?? $relation->name;
        $relation->name = $name;
        $this->relations[$name] = $relation;
        return $this;
    }
753341
public function addDiscriminator(string $class, string $key, string $discriminatorClass): void
    {
        if (!isset($this->discriminators[$class])) {
            $this->discriminators[$class] = [];
        }

        if (!isset($this->discriminators[$class][$key])) {
            $this->discriminators[$class][$key] = $discriminatorClass;
        }
    }
91646
public function createResource($class, $name)
    {
        $entity = $this->om->factory($class);

        if ($entity instanceof \Claroline\CoreBundle\Entity\Resource\AbstractResource) {
            $entity->setName($name);

            return $entity;
        }

        throw new WrongClassException(
            "{$class} doesn't extend Claroline\CoreBundle\Entity\Resource\AbstractResource."
        );
    }
1020703
protected function storeRelationship(string $class, string $dependency): void
    {
        $this->relationships[$class][$dependency] = true;

        if (isset($this->relationships[$class][$dependency]) && isset($this->relationships[$dependency][$class])) {
            throw new ContainerException(sprintf(
                'Cyclical dependency found between `%s` and `%s`.',
                $class,
                $dependency
            ));
        }
    }
776375
public function setLazy($entity, $name, $value)
    {
        // Verify if virtual property exists, if not then just don't set it!
        if (! in_array($name, $this->getEntityStructure($entity)->relationProperties)) {
            return;
        }

        // Verify if value is also an entity!
        if (! $value instanceof Entity && $value !== null) {
            throw new RelationException("Property '".$name."' is a reference to a relationship, you should set the entity of that relationship!");
        }

        // Pass to the relationmanager
        RelationManager::with($entity)->set($name, $value);
    }
1207851
public static function getRelationDefinition($name)
    {
        if (!isset(static::$relations[$name])) {
            throw new \Exception(sprintf('Relation "%s" of Entity "%s" is not defined', $name, get_called_class()));
        }
        $relation = static::$relations[$name];
        if (count($relation) !== 4) {
            throw new \Exception(sprintf('Relation "%s" of Entity "%s" is invalid', $name, get_called_class()));
        }

        return $relation;
    }
1137156
public function Identify($name, $class)
    {
        $method = 'make'.lcfirst($name);
        if(method_exists($this, $method))
            $this->{$name}($class);
    }
512625
public function getRelationshipEntityPersister($class)
    {
        if (!array_key_exists($class, $this->relationshipEntityPersisters)) {
            $classMetadata = $this->entityManager->getRelationshipEntityMetadata($class);
            $this->relationshipEntityPersisters[$class] = new RelationshipEntityPersister($this->entityManager, $class, $classMetadata);
        }

        return $this->relationshipEntityPersisters[$class];
    }
234334
protected function checkRelationClass($class, $component, $relationClass, $type)
    {
        if (!is_string($component) || is_numeric($component)) {
            throw new InvalidArgumentException(
                "{$class} has invalid {$type} relation name"
            );
        }
        if (!is_string($relationClass)) {
            throw new InvalidArgumentException(
                "{$type} relation {$class}.{$component} is not a class name"
            );
        }
        if (!class_exists($relationClass)) {
            throw new InvalidArgumentException(
                "{$type} relation {$class}.{$component} references class {$relationClass} which doesn't exist"
            );
        }
        // Support polymorphic has_one
        if ($type === 'has_one') {
            $valid = is_a($relationClass, DataObject::class, true);
        } else {
            $valid = is_subclass_of($relationClass, DataObject::class, true);
        }
        if (!$valid) {
            throw new InvalidArgumentException(
                "{$type} relation {$class}.{$component} references class {$relationClass} "
                . " which is not a subclass of " . DataObject::class
            );
        }
    }
1320260
protected function define(ClassDefinition $class)
    {
        $class->property($this->name)->asString();

        $class->property($this->value)->asString();
    }
47402
public function addNamedNativeQueryResultSetMapping(ClassMetadataInfo $class, $resultSetMappingName)
    {
        $counter        = 0;
        $resultMapping  = $class->getSqlResultSetMapping($resultSetMappingName);
        $rooShortName   = $class->reflClass->getShortName();
        $rootAlias      = strtolower($rooShortName[0]) . $counter;


        if (isset($resultMapping['entities'])) {
            foreach ($resultMapping['entities'] as $key => $entityMapping) {
                $classMetadata  = $this->em->getClassMetadata($entityMapping['entityClass']);

                if ($class->reflClass->name == $classMetadata->reflClass->name) {
                    $this->addEntityResult($classMetadata->name, $rootAlias);
                    $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $rootAlias);
                } else {
                    $shortName      = $classMetadata->reflClass->getShortName();
                    $joinAlias      = strtolower($shortName[0]) . ++ $counter;
                    $associations   = $class->getAssociationsByTargetClass($classMetadata->name);

                    foreach ($associations as $relation => $mapping) {
                        $this->addJoinedEntityResult($mapping['targetEntity'], $joinAlias, $rootAlias, $relation);
                        $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias);
                    }
                }

            }
        }

        if (isset($resultMapping['columns'])) {
            foreach ($resultMapping['columns'] as $entityMapping) {
                $this->addScalarResult($entityMapping['name'], $entityMapping['name']);
            }
        }

        return $this;
    }
95553
private function getRelationFromDb($name)
    {
        if (!$this->relationsParser) {
            $this->relationsParser = RelationsParser::parse(get_class($this), new ModelCondition(['model' => get_class($this)]), '*');
        }
        return $this->relationsParser->getForSingleModel($this, $name);
    }
353808
private function hydrateRelation($entity, $name, $value)
    {
        $relationClass = $this->em
            ->getClassMetadata(get_class($entity))
            ->getAssociationMapping($name)["targetEntity"]
        ;

        $relation = $entity->{"get".Inflector::camelize($name)}();
        if(in_array('id', array_keys($value))) {
            $relation = $this->em->getRepository($relationClass)->find($value['id']);
            unset($value['id']);
        } elseif(empty($relation)) {
            $relation = new $relationClass;
        }

        return $this->hydrate($relation, $value);
    }
1089298
public function renameRelation(string $name, string $new) : array
    {
        if (!isset($this->relations[$name])) {
            throw new DBException("Relation not found");
        }
        if (isset($this->relations[$new])) {
            throw new DBException("A relation with that name already exists");
        }
        $temp = $this->relations[$name];
        $temp->name = $new;
        $this->relations[$new] = $temp;
        unset($this->relations[$name]);
        return $this->relations[$new] ?? null;
    }
1003685
protected function addClass(string $class)
    {
        if ($this->initialized) {
            throw new RuntimeException("You can't register provider class as registry as been initialized.");
        }

        if (!class_exists($class)) {
            throw new InvalidArgumentException("Class $class does not exist.");
        }

        if (!is_subclass_of($class, ProviderInterface::class)) {
            throw new InvalidArgumentException("Class $class must implement " . ProviderInterface::class);
        }

        $this->classes[] = $class;
    }
735451
protected function processModelAsArray($data, $relation, $name)
    {
        /** @var BaseActiveRecord $modelClass */
        $modelClass = $relation->modelClass;
        $fks = $this->_getRelatedFks($data, $relation, $modelClass);
        return $this->_loadOrCreateRelationModel($data, $fks, $modelClass, $name);
    }