Allow to configure hints for the QueryBuilder#6359
Closed
sstok wants to merge 1 commit intodoctrine:masterfrom
Closed
Allow to configure hints for the QueryBuilder#6359sstok wants to merge 1 commit intodoctrine:masterfrom
sstok wants to merge 1 commit intodoctrine:masterfrom
Conversation
Author
|
Travis failures seem unrelated 😃 |
a7f3d50 to
7fb926c
Compare
issei-m
reviewed
Mar 26, 2017
7fb926c to
d440e7c
Compare
Member
|
But what's wrong with |
Author
|
The Query is generated after the building process, so I don't have any control over it. In the case an extension is able to provide the data, I set the Query hint as follow: public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
{
$request = $this->requestStack->getCurrentRequest();
/** @var SearchCondition $condition */
if (!$request || null === $condition = $request->attributes->get('_api_search_condition')) {
return;
}
if (!method_exists($queryBuilder, 'setHint')) {
return;
}
$fieldSetName = $condition->getFieldSet();
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
if (null !== $attributes = $resourceMetadata->getAttribute('rollerworks_search')) {
return;
}
if (empty($attributes['doctrine_orm']['*']) && empty($attributes['doctrine_orm'][$fieldSetName])) {
return;
}
if (isset($resourceMetadata['accepted_fieldsets'])) {
$condition->assertFieldSetName(...array_push($resourceMetadata['accepted_fieldsets'], $resourceClass));
}
$fieldSetName = $condition->getFieldSet();
$setName = isset($attributes['doctrine_orm'][$fieldSetName]) ? $fieldSetName : '*';
$configuration = $attributes['doctrine_orm'][$setName];
$this->configureRelations($resourceClass, $configuration, $setName, $queryBuilder);
$query = $queryBuilder->getEntityManager()->createQuery(); // Dummy to get the EntityManager
$conditionGenerator = $this->ormFactory->createCachedConditionGenerator($this->ormFactory->createConditionGenerator($query, $condition));
$this->configureMappings($resourceClass, $configuration, $setName, $conditionGenerator);
$queryBuilder->andWhere($conditionGenerator->getWhereClause());
$queryBuilder->setHint($conditionGenerator->getQueryHintName(), $conditionGenerator->getQueryHintValue()); // This cannot be done afterwards,
} |
sstok
added a commit
to rollersearch/search-doctrine-orm
that referenced
this pull request
Mar 28, 2017
This PR was merged into the 2.0-dev branch. Discussion ---------- | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This allow QueryBuilder to be used when the required method exists ( doctrine/orm#6359 ). For now it's an undocumented feature, mainly for the Apl-Platform integration (testing is near impossible without this). Commits ------- 78aa9e0 Allow QueryBuilder when hints are supported
Author
|
Notice. I no longer need this feature as it's solved different in rollersearch/search#286 Feel free to close this 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background: In the RollerworksSearch (Doctrine ORM ConditionGenerator) I use a Query-Hint to pass conversion information to DQL functions. But now to integrate RollerworksSearch with the Api-platform I need to work with the QueryBuilder which doesn't allow to set hints.
I copied the description from the AbstractQuery class. If possible can this be back ported to 2.5 also? I know you prefer to merge everything to master but without this I'm kinda stuck, and I don't know when 2.6 will be released 😅