Bug #26885

It's not possible to order by relation properties

Added by Bastian Waidelich over 10 years ago. Updated almost 10 years ago.

Status:
Resolved
Priority:
Should have
Category:
Persistence
Target version:
-
Start date:
2011-05-18
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

The following code (in a custom repository) won't work if "proposedSessionType" is a relation..

protected $defaultOrderings = array(
    'proposedSessionType' => QueryInterface::ORDER_ASCENDING,
);

Also it does not work to order by properties of a relation like:

protected $defaultOrderings = array(
    'proposedSessionType.title' => QueryInterface::ORDER_ASCENDING,
);


Files

patch.jpg (9.03 KB) patch.jpg Bastian Waidelich, 2011-05-18 22:03
issue26885.patch (1.2 KB) issue26885.patch Ferdinand Kuhl, 2011-08-27 15:09
#1

Updated by Karsten Dambekalns over 10 years ago

  • Status changed from New to Accepted
#2

Updated by Ferdinand Kuhl about 10 years ago

a bit more on this issue: setOrderings() appends rootAlias . "proposedSessionType" 
to the orderBy-Clause. And appearently multi-dot-notation has been dropped 
shortly by doctrine:

http://www.doctrine-project.org/projects/orm/2.1/docs/whats-new/en

The only possibility I can see at the moment is detect "." in the argument, 
do a join for this table and rewrite the order by statement.

Has anyone problems with that? Should I try to prepare a patch?

#3

Updated by Ferdinand Kuhl about 10 years ago

Great! As there is already a method "getPropertyNameWithAlias" its extremely easy to fix this:

Just change

public function setOrderings(array $orderings) {
        $this->orderings = $orderings;
        $this->queryBuilder->resetDQLPart('orderBy');
        foreach ($this->orderings AS $propertyName => $order) {
            $this->queryBuilder->addOrderBy($this->queryBuilder->getRootAlias() . '.' . $propertyName, $order);

        }
        return $this;
    }

to

public function setOrderings(array $orderings) {
        $this->orderings = $orderings;
        $this->queryBuilder->resetDQLPart('orderBy');
        foreach ($this->orderings AS $propertyName => $order) {
            $this->queryBuilder->addOrderBy($this->getPropertyNameWithAlias($propertyName), $order);
        }
        return $this;
    }
#4

Updated by Ferdinand Kuhl about 10 years ago

Prepared a patch using git, but as I have not yet signed the CLA I am not allowed to commit it to gerrit.

Hope it helps to speed things up. Have I really have to send a fax?

#5

Updated by Mr. Hudson about 10 years ago

  • Status changed from Accepted to Under Review

Patch set 1 of change Ib6d967ccc97ed64828bea8765edea5dd8c63aa0a has been pushed to the review server.
It is available at http://review.typo3.org/4725

#6

Updated by Mr. Hudson about 10 years ago

Patch set 2 of change Ib6d967ccc97ed64828bea8765edea5dd8c63aa0a has been pushed to the review server.
It is available at http://review.typo3.org/4725

#8

Updated by Sebastian Kurfuerst almost 10 years ago

  • Status changed from Under Review to Resolved
  • Has patch set to No

already merged long ago

Also available in: Atom PDF