You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When looking at the custom filters documentation there's multiple example of custom filters, but with different "alias".
There's this first example with o used as an hardcoded alias (REGEXP(o.%s, :%s)).
protectedfunctionfilterProperty(string$property, $value, QueryBuilder$queryBuilder, QueryNameGeneratorInterface$queryNameGenerator, string$resourceClass, Operation$operation = null, array$context = [])
{
// otherwise filter is applied to order and page as wellif (
!$this->isPropertyEnabled($property, $resourceClass) ||
!$this->isPropertyMapped($property, $resourceClass)
) {
return;
}
$parameterName = $queryNameGenerator->generateParameterName($property); // Generate a unique parameter name to avoid collisions with other filters$queryBuilder
->andWhere(sprintf('REGEXP(o.%s, :%s) = 1', $property, $parameterName))
->setParameter($parameterName, $value);
}
Others example use the rootAliases :
//App/Filter/CustomAndFilter.phpprotectedfunctionfilterProperty(string$property, $value, QueryBuilder$queryBuilder, QueryNameGeneratorInterface$queryNameGenerator, string$resourceClass, Operation$operation = null, array$context = []) {
$rootAlias = $queryBuilder->getRootAliases()[0];
foreach (array_keys($this->getProperties()) as$prop) { //NOTE: we use array_keys because getProperties() returns a map of property => strategyif (!$this->isPropertyEnabled($prop, $resourceClass) || !$this->isPropertyMapped($prop, $resourceClass)) {
return;
}
$parameterName = $queryNameGenerator->generateParameterName($prop);
$queryBuilder
->andWhere(sprintf('%s.%s LIKE :%s', $rootAlias, $prop, $parameterName))
->setParameter($parameterName, "%" . $value . "%");
}
}
Is there any reason that o was used as an alias in the first example ? What could it do if I use the same hardcoded alias (o) in my project ?
The text was updated successfully, but these errors were encountered:
When looking at the custom filters documentation there's multiple example of custom filters, but with different "alias".
There's this first example with
o
used as an hardcoded alias (REGEXP(o.%s, :%s)
).Others example use the rootAliases :
Is there any reason that
o
was used as an alias in the first example ? What could it do if I use the same hardcoded alias (o
) in my project ?The text was updated successfully, but these errors were encountered: