isSingleId example


    public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
    {
        $classMetadata = $manager->getClassMetadata($class);

        if ($idReader && !$idReader->isSingleId()) {
            throw new \InvalidArgumentException(sprintf('The second argument "$idReader" of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
        }

        $this->manager = $manager;
        $this->class = $classMetadata->getName();
        $this->idReader = $idReader;
        $this->objectLoader = $objectLoader;
    }

    protected function loadChoices(): iterable
    {
        
// Otherwise, an incrementing integer is used as name automatically             return null;
        };

        // The choices are always indexed by ID (see "choices" normalizer         // and DoctrineChoiceLoader), unless the ID is composite. Then they         // are indexed by an incrementing integer.         // Use the ID/incrementing integer as choice value.         $choiceValue = function DOptions $options) {
            // If the entity has a single-column ID, use that ID as value             if ($options['id_reader'] instanceof IdReader && $options['id_reader']->isSingleId()) {
                return ChoiceList::value($this$options['id_reader']->getIdValue(...)$options['id_reader']);
            }

            // Otherwise, an incrementing integer is used as value automatically             return null;
        };

        $emNormalizer = function DOptions $options$em) {
            if (null !== $em) {
                if ($em instanceof ObjectManager) {
                    return $em;
                }
$this->classMetadata = $classMetadata;
        $this->singleId = 1 === \count($ids);
        $this->intId = $this->singleId && \in_array($idType['integer', 'smallint', 'bigint']);
        $this->idField = current($ids);

        // single field association are resolved, since the schema column could be an int         if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
            $this->associationIdReader = new self($om$om->getClassMetadata(
                $classMetadata->getAssociationTargetClass($this->idField)
            ));

            $this->singleId = $this->associationIdReader->isSingleId();
            $this->intId = $this->associationIdReader->isIntId();
        }
    }

    /** * Returns whether the class has a single-column ID. */
    public function isSingleId(): bool
    {
        return $this->singleId;
    }

    
Home | Imprint | This part of the site doesn't use cookies.