Code Monkey home page Code Monkey logo

Comments (7)

cedric-g avatar cedric-g commented on July 21, 2024

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.

cedric-g avatar cedric-g commented on July 21, 2024

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.

inoryy avatar inoryy commented on July 21, 2024

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.

cedric-g avatar cedric-g commented on July 21, 2024

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.

zerkalica avatar zerkalica commented on July 21, 2024

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.

cedric-g avatar cedric-g commented on July 21, 2024

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.

inoryy avatar inoryy commented on July 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.