-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to configure hints for the QueryBuilder #6359
Conversation
Travis failures seem unrelated 😃 |
a7f3d50
to
7fb926c
Compare
7fb926c
to
d440e7c
Compare
But what's wrong with |
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,
} |
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
Notice. I no longer need this feature as it's solved different in rollerworks/search#286 Feel free to close this 👍 |
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 😅