Easyadminbundle: OneToOne list sorting bug

Created on 23 Mar 2016  路  6Comments  路  Source: EasyCorp/EasyAdminBundle

This happens, when you sort by the relation:

?action=list&entity=Subscription&menuIndex=0&submenuIndex=-1&sortField=transaction&sortDirection=DESC&page=1
Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinColumnName()
must be of the type array, boolean given

It seems that is caused by a OneToOne relation:

     /**
      * @ORM\OneToOne(targetEntity="AppBundle\Entity\Transaction", mappedBy="subscription")
      */
    private $transaction;
bug unconfirmed

Most helpful comment

Hi, I still have this problem with EasyAdmin 1.17.19, Symfony 4.2.1, Doctrine Bundle 1.10

When I try to order an entity from the 'list' action by another entity which has a one-to-one relationship and its relation has not yet been defined or was eliminated (that is, it has null value as a relation) I get this error:

Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinColumnName() must be of the type array, boolean given, called in C:\test\Emdupar\vendor\doctrine\orm\lib\Doctrine\ORM\Query\AST\Functions\IdentityFunction.php on line 89

    /**
     * @ORM\OneToOne(
     *     targetEntity="App\Entity\Model\InvoiceOwnerInterface",
     *     mappedBy="invoice",
     *     cascade={"persist","remove"}
     *     )
     */
    private $service;

All 6 comments

Similar happening to me on 1.12.6, symfony 2.8.4, Doctrine Bundle 1.4

[2/2] An exception has been thrown during the rendering of a template ("Notice: Undefined index: airportData") in @EasyAdmin/default/list.html.twig at line 129.

[1/2] ContextErrorException: Notice: Undefined index: airportData -
in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php at line 40

When trying to sort by OneToOne

     /**
     * @var string
     *
     * @ORM\OneToOne(targetEntity="AppBundle\Entity\AirportsMasterData", fetch="EAGER")
     */
    private $airportData;

Found the issue (at least part of it) in Search/Paginator.php

$paginator = new Pagerfanta(new DoctrineORMAdapter($queryBuilder, true, false));

DoctrineORMAdapter second parameter ($fetchJoinCollection), if set to true returns Object without associated field, if set to false returns Object with associated field.

Investigating further...

I'm possibly hijacking this issue, as my issue might be different but still related.
Let me know if you want me to open new issue.

On the matter:

I was able to fix my issue by defining custom ListQueryBuilder where I'm explicitly joining my relation.

Relation (One To One unidirectional):

/**
     * @var string
     *
     * @ORM\OneToOne(targetEntity="AppBundle\Entity\AirportsMasterData", fetch="EAGER")
     */
    private $airportData;

Custom ListQueryBuilder:

protected function createMonitoredAirportsListQueryBuilder($entityConfig, $sortDirection, $sortField)
    {
        /** @var EntityManager */
        $em = $this->get('doctrine')->getManagerForClass($entityConfig);

        $queryBuilder = $em->createQueryBuilder()
            ->select(array('entity', 'ad'))
            ->from($entityConfig, 'entity')
            ->leftJoin('entity.airportData', 'ad');

        if (null !== $sortField) {
            if ($sortField == "airportData") {
                $queryBuilder->orderBy('ad.airportIcao', $sortDirection);
            } else {
                $queryBuilder->orderBy('entity.'.$sortField, $sortDirection);
            }
        }

        return $queryBuilder;
    }

Note that I'm joining on my OneToOne relation and then doing custom orderBy if sortField is my OneToOne relation.

Snippet of my AirportsMasterData:

class AirportsMasterData
{
    public function __toString()
    {
        return $this->airportIcao;
    }

    /**
     * @var string
     *
     * @ORM\Column(name="airport_icao", type="string", length=4, unique=true)
     */
    private $airportIcao;

Questions I have remaining:

  1. Am I doing something wrong when I get "undefined index" error in my original issue? EasyAdmin should at least attempt to sort by relation id. Right or wrong? It works when _DoctrineORMAdapter_ is called with _fetchJoinCollection_ as false (please ref my previous comment). doctrine:schema:validate shows all OK.
  2. Is custom ListQueryBuilder the correct way to resolve this or the expectation is that EasyAdmin should work with that by default? (sort of related to 1st question)
  3. Not sure how to implement this - but would it be a good idea for EasyAdmin to have an option to define how to sort on related field? i.e. in my example I have to define custom ListQueryBuilder to say that I wan't to sort on ad.airportIcao (from related table) instead of sorting on relation IDs. It is also the same field that __toString returns.

Dear @javiereguiluz , appreciate if you can comment whenever possible.

Closing it as (probably) fixed by #1392, which allows to sort results by any property of a Doctrine association.

Hi, I still have this problem with EasyAdmin 1.17.19, Symfony 4.2.1, Doctrine Bundle 1.10

When I try to order an entity from the 'list' action by another entity which has a one-to-one relationship and its relation has not yet been defined or was eliminated (that is, it has null value as a relation) I get this error:

Argument 1 passed to Doctrine\ORM\Mapping\DefaultQuoteStrategy::getJoinColumnName() must be of the type array, boolean given, called in C:\test\Emdupar\vendor\doctrine\orm\lib\Doctrine\ORM\Query\AST\Functions\IdentityFunction.php on line 89

    /**
     * @ORM\OneToOne(
     *     targetEntity="App\Entity\Model\InvoiceOwnerInterface",
     *     mappedBy="invoice",
     *     cascade={"persist","remove"}
     *     )
     */
    private $service;

@TavoNiievez Me, too!

Was this page helpful?
0 / 5 - 0 ratings