Skip to content

Commit

Permalink
Allow CollectionDataProvider decoration to add query hints
Browse files Browse the repository at this point in the history
  • Loading branch information
abluchet committed Sep 6, 2016
1 parent 583d234 commit 6568143
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Bridge/Doctrine/Orm/CollectionDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
use ApiPlatform\Core\Exception\RuntimeException;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;

/**
* Collection data provider for the Doctrine ORM.
Expand All @@ -40,6 +42,20 @@ public function __construct(ManagerRegistry $managerRegistry, array $collectionE
$this->collectionExtensions = $collectionExtensions;
}

/**
* Allow to customize the Query object
* For example you can force doctrine to not load lazy relations by using:
* $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true).
*
* @param QueryBuilder
*
* @return Query
*/
public function getQuery(QueryBuilder $queryBuilder): Query
{
return $queryBuilder->getQuery();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -67,6 +83,6 @@ public function getCollection(string $resourceClass, string $operationName = nul
}
}

return $queryBuilder->getQuery()->getResult();
return $this->getQuery($queryBuilder)->getResult();
}
}
15 changes: 15 additions & 0 deletions src/Bridge/Doctrine/Orm/ItemDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;

/**
Expand Down Expand Up @@ -50,6 +51,20 @@ public function __construct(ManagerRegistry $managerRegistry, PropertyNameCollec
$this->itemExtensions = $itemExtensions;
}

/**
* Allow to customize the Query object
* For example you can force doctrine to not load lazy relations by using:
* $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true).
*
* @param QueryBuilder
*
* @return Query
*/
public function getQuery(QueryBuilder $queryBuilder): Query
{
return $queryBuilder->getQuery();
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 6568143

Please sign in to comment.