Neos\Flow\Persistence\Doctrine\Query::setLimit PHP Method

setLimit() public method

Sets the maximum size of the result set to limit. Returns $this to allow for chaining (fluid interface)
public setLimit ( integer $limit ) : Neos\Flow\Persistence\QueryInterface
$limit integer
return Neos\Flow\Persistence\QueryInterface
    public function setLimit($limit)
    {
        $this->limit = $limit;
        $this->queryBuilder->setMaxResults($limit);
        return $this;
    }

Usage Example

コード例 #1
0
 /**
  * @test
  */
 public function countRespectsLimitConstraint()
 {
     $testEntityRepository = new Fixtures\TestEntityRepository();
     $testEntityRepository->removeAll();
     $testEntity1 = new Fixtures\TestEntity();
     $testEntity1->setName('Flow');
     $testEntityRepository->add($testEntity1);
     $testEntity2 = new Fixtures\TestEntity();
     $testEntity2->setName('some');
     $testEntityRepository->add($testEntity2);
     $testEntity3 = new Fixtures\TestEntity();
     $testEntity3->setName('more');
     $testEntityRepository->add($testEntity3);
     $this->persistenceManager->persistAll();
     $query = new Query(Fixtures\TestEntity::class);
     $this->assertEquals(2, $query->setLimit(2)->execute()->count());
 }