Comments (7)
Maybe we can change Filter\QueryBuilder::buildQuery()
to make the method look for children. But we need to know the relation's name to add the join on the Doctrine QueryBuilder instance. We also need to pass the relation alias to the FilterTypeInterface::applyFilter()
method and update it to use this alias instead of the root alias.
from lexikformfilterbundle.
I pushed a new embedFilter
branch with some changes to supports embedded form filters :)
An embedded form filter type need to implement EmbeddedFilterInterface
. The Filter\QueryBuilder
class now checks if the form instance was created from a Type implementing EmbeddedFilterInterface
, if yes we add a join and the conditions from embedded form filter fields.
You can also have a look to Tests\Filter\QueryBuilderTest::testEmbedFormFilter()
.
from lexikformfilterbundle.
First of all, this works really great, so big thanks on your hard work! :)
But there's a small bug: if queryBuilder already has a join in it, then EmbedFilter will init a second one, instead of reusing it.
Example: I pre-build qb which joins to Test
. Then I try to filter something by result
. I end up with DQL like:
SELECT st FROM Student st LEFT JOIN st.test test LEFT JOIN st.test test WHERE test.result = :result
P.S. FYI I'm not sure if it's even possible to check if qb already has a join or not, so maybe this issue is out of scope for this bundle.
from lexikformfilterbundle.
Doctrine seems to keep joins as a DQL part, a join is represented by an instance of Doctrine\ORM\Query\Expr\Join
but all properties of this class are private :(
So I just added a setJoins()
method in the Filter\QueryBuilder
class, now you can do something like this:
$filterQueryBuilder
->setJoins(array('st.test' => 't')) // 'relation' => 'alias'
->buildQuery($form, $doctrineQueryBuilder);
from lexikformfilterbundle.
I think, it's not usable for more complex cases with multiple joins, combination of left and inner joins, conditions in joins:
SELECT * FROM Value
JOIN stringValue vs1
JOIN vs1.abstractValue av1
JOIN av1.field f1 ON f1.type= 'string'
WHERE vs1 = 'test'
May be delegate joins actions to EmbedFormType method:
//buildQuery:
if ($type instanceof EmbeddedFilterInterface) {
$qbe = new QueryBuilderExecuter($queryBuilder, $alias, $this->expr, $this->parts);
$type->addShared($qbe);
$this->parts = $qbe->getParts();
}
//addShared:
$qbe->addOnce('s_' . $qbe->getAlias(), function(QueryBuilder $queryBuilder, $alias, $joinAlias, Expr $e) {
$queryBuilder->leftJoin($alias . '.status', $joinAlias, 'ON', $e->eq($joinAlias . '.status', 1));
});
class QueryBuilderExecuter
{
...
public function addOnce($tag, \Callback $callback)
{
if (isset($this->parts[$tag])) {
return null;
}
$this->parts[$tag] = true;
return $callback($this->queryBuilder, $this->alias, $tag, $this->expr);
}
}
from lexikformfilterbundle.
No, the current version does not work with complex cases, so thanks for the code sample. I will try to implement something like you suggest.
from lexikformfilterbundle.
@cedric-g this ticket seems to be solved from my end, so unless @zerkalica wants to add something in, it's good for closing
from lexikformfilterbundle.
Related Issues (20)
- Mongo as separate packages? HOT 2
- v5.0.9 Broken with symfony 3.4 HOT 2
- Service "lexik_form_filter.query_builder_updater" not found HOT 4
- doctrine/orm v2.6.4 has issues with using ChoiceFilterType with objects
- NumberRangeFilterType can not set attribute " type:'number' '' , and 'label' is not work as well HOT 3
- CollectionAdapterFilterType display an unwanted "level" with a label : "0" HOT 2
- Store Entity in session HOT 1
- Not a issue, change repo description HOT 1
- How to have more user/search engines friendly urls
- Works in symfony 5.1 ? HOT 1
- How to add a field to set maxresults HOT 1
- Options 'data' does not work for EntityFilterType
- Hi HOT 3
- Undefined class constant 'INTEGER' when filtering EntityFilterType HOT 2
- doctrine/orm to specific HOT 1
- Using ChoiceFilterType generate: Undefined constant Doctrine\DBAL\Types\Type::STRING HOT 1
- Ltrim issue in LexikFormFilterBundle/Event/Subscriber/DoctrineORMSubscriber.php
- Filter by entity with string id HOT 3
- Feature Request: Allow using array based $parameters with IN() expressions HOT 2
- Bundle abandonned...and moved on new organization!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lexikformfilterbundle.