protected function loadRelations(array $roles, $buildDepth=BuildDepth::SINGLE) {
    $oldState = $this->getState();
    foreach ($roles as $curRole) {
      if (isset($this->relationStates[$curRole]) &&
              $this->relationStates[$curRole] != self::RELATION_STATE_LOADED) {
        $relatives = [];

        // resolve proxies if the relation is already initialized
        if ($this->relationStates[$curRole] == self::RELATION_STATE_INITIALIZED) {
          $proxies = $this->getValue($curRole);
          if (is_array($proxies)) {
            foreach ($proxies as $curRelative) {
              if ($curRelative instanceof PersistentObjectProxy) {
                // resolve proxies
                $curRelative->resolve($buildDepth);
                $relatives[] = $curRelative->getRealSubject();
              }
              else {
                $relatives[] = $curRelative;
              }
            }
          }
        }
        // otherwise load the objects directly
        else {
          $mapper = $this->getMapper();
          $allRelatives = $mapper->loadRelation([$this], $curRole, $buildDepth);
          $oidStr = $this->getOID()->__toString();
          $relatives = isset($allRelatives[$oidStr]) ? $allRelatives[$oidStr] : null;
          $relDesc = $mapper->getRelation($curRole);
          if (!$relDesc->isMultiValued()) {
            $relatives = $relatives != null ? $relatives[0] : null;
          }
        }
        $this->setValueInternal($curRole, $relatives);
        $this->relationStates[$curRole] = self::RELATION_STATE_LOADED;
      }
    }
    $this->setState($oldState);
  }