Doctrine\ODM\MongoDB\Mapping\MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy PHP Method

referenceManySortMustNotBeUsedWithNonSetCollectionStrategy() public static method

public static referenceManySortMustNotBeUsedWithNonSetCollectionStrategy ( string $className, string $fieldName, string $strategy ) : MappingException
$className string
$fieldName string
$strategy string
return MappingException
    public static function referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($className, $fieldName, $strategy)
    {
        return new self("ReferenceMany's sort can not be used with addToSet and pushAll strategies, {$strategy} used in {$className}::{$fieldName}");
    }

Usage Example

 /**
  * Validates the storage strategy of a mapping for consistency
  * @param array $mapping
  * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException
  */
 private function applyStorageStrategy(array &$mapping)
 {
     if (!isset($mapping['type']) || isset($mapping['id'])) {
         return;
     }
     switch (true) {
         case $mapping['type'] == 'int':
         case $mapping['type'] == 'float':
         case $mapping['type'] == 'increment':
             $defaultStrategy = self::STORAGE_STRATEGY_SET;
             $allowedStrategies = [self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_INCREMENT];
             break;
         case $mapping['type'] == 'many':
             $defaultStrategy = CollectionHelper::DEFAULT_STRATEGY;
             $allowedStrategies = [self::STORAGE_STRATEGY_PUSH_ALL, self::STORAGE_STRATEGY_ADD_TO_SET, self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_SET_ARRAY, self::STORAGE_STRATEGY_ATOMIC_SET, self::STORAGE_STRATEGY_ATOMIC_SET_ARRAY];
             break;
         default:
             $defaultStrategy = self::STORAGE_STRATEGY_SET;
             $allowedStrategies = [self::STORAGE_STRATEGY_SET];
     }
     if (!isset($mapping['strategy'])) {
         $mapping['strategy'] = $defaultStrategy;
     }
     if (!in_array($mapping['strategy'], $allowedStrategies)) {
         throw MappingException::invalidStorageStrategy($this->name, $mapping['fieldName'], $mapping['type'], $mapping['strategy']);
     }
     if (isset($mapping['reference']) && $mapping['type'] === 'many' && $mapping['isOwningSide'] && !empty($mapping['sort']) && !CollectionHelper::usesSet($mapping['strategy'])) {
         throw MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($this->name, $mapping['fieldName'], $mapping['strategy']);
     }
 }
All Usage Examples Of Doctrine\ODM\MongoDB\Mapping\MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy