Giter VIP home page Giter VIP logo

Comments (4)

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

Hi, I'm not sure to understand, do you need to filter Lesson entities with some null values ? or elements which are not related to a Lesson entity ?

from lexikformfilterbundle.

byhoratiss avatar byhoratiss commented on July 17, 2024

I think he needs that "lesson" be NULL, or the "empty_data" field is the problem? Cant imagine what are you trying to achieve.

from lexikformfilterbundle.

salemgolemugoo avatar salemgolemugoo commented on July 17, 2024

See. I have 2 entities with an OneToMany relation. Join column can be NULL. When I filter entity by join column, I can't get entities with a NULL join column, because there is no such row in filter_entity widget. When no filter is used, i receive all of this entities, but I want receive only with a NULL join column.

from lexikformfilterbundle.

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

Ok, so I think the easiest way to do it would be to override the EntityFilter listener to add a condition on the query builder in case of the value is null, so you can do something like:

namespace Custom\Filter\ORM\Filters;

use Doctrine\ORM\QueryBuilder;
use Lexik\Bundle\FormFilterBundle\Filter\ORM\Filters\EntityFilter as BaseEntityFilter;
use Lexik\Bundle\FormFilterBundle\Filter\ORM\Expr;

class EntityFilter extends BaseEntityFilter
{
    /**
     * {@inheritdoc}
     */
    protected function apply(QueryBuilder $queryBuilder, Expr $expr, $field, array $values)
    {
        if (null === $values['value']) {
            $queryBuilder->andWhere($expr->isNull($field));

            return;
        } 

        parent::apply($queryBuilder, $expr, $field, $values);
    }
}

Then override the service definition:

<service id="lexik_form_filter.entity" class="Custom\Filter\ORM\Filters\EntityFilter">
    <tag name="kernel.event_listener" event="lexik_filter.get" method="onFilterGet" />
</service>

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.