getEntitiesByIds example

// Optimize performance in case we have an object loader and         // a single-field identifier         if ($idReader && $this->objectLoader) {
            $objects = [];
            $objectsById = [];

            // Maintain order and indices from the given $values             // An alternative approach to the following loop is to add the             // "INDEX BY" clause to the Doctrine query in the loader,             // but I'm not sure whether that's doable in a generic fashion.             foreach ($this->objectLoader->getEntitiesByIds($idReader->getIdField()$values) as $object) {
                $objectsById[$idReader->getIdValue($object)] = $object;
            }

            foreach ($values as $i => $id) {
                if (isset($objectsById[$id])) {
                    $objects[$i] = $objectsById[$id];
                }
            }

            return $objects;
        }

        
->onlyMethods(['getQuery'])
            ->getMock();

        $qb->expects($this->once())
            ->method('getQuery')
            ->willReturn($query);

        $qb->select('e')
            ->from($classname, 'e');

        $loader = new ORMQueryBuilderLoader($qb);
        $loader->getEntitiesByIds('id', [1, 2]);
    }

    public function testFilterNonIntegerValues()
    {
        $em = DoctrineTestHelper::createTestEntityManager();

        $query = $this->getMockBuilder(QueryMock::class)
            ->onlyMethods(['setParameter', 'getResult', 'getSql', '_doExecute'])
            ->getMock();

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