Cold_Class
Cold_Class

Reputation: 3484

Query with orderings causing empty result - Extbase 6.2

I made an extbase extension and want to list my appointments ordered first by startDate and for those appointments that are on the same day I want to order them by the last name of the customer.
In my repository I made following working query:

public function findAppointmentsForList($future) {
    $curtime = time();
    $query = $this->createQuery();
    $constraints = array();
    if ($future !== NULL) {
        $constraints[] = ($future) ?
                $query->greaterThanOrEqual('startDate', $curtime) :
                $query->lessThan('startDate', $curtime);
    }

    if ($constraints) {
        $query->matching($query->logicalAnd($constraints));
    } else {}

    $orderings = array(
        'startDate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
//            'customer.lastName' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
    );
    $query->setOrderings($orderings);
    return $query->execute();
}

It returns me some appointments so I assume it's working.
If I then uncomment the line 'customer.lastName... it returns 0 appointments.
What's going on? It's just the ordering, it can't possibly make the query smaller...
I don't even get any errors - I tried it with an invalid property for example and it gave me an error, so the property name is correct too.
And I debugged the working query and the last names in those customer objects where there.

This is my appointment model entry:

/**
* customer
*
* @var \vendor\extension\Domain\Model\Customer
*/
protected $customer = NULL;

And this is the TCA corresponding to it:

'customer' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension_domain_model_appointment.customer',
        'config' => array(
                'type' => 'select',
                'foreign_table' => 'fe_users',
                'minitems' => 0,
                'maxitems' => 1,
        ),
),

EDIT: It's working now...but unfortunately I don't know why, changed too much in the meantime which I thought had nothing to do with this. One thing that might've affected this: startDate is of type Date and I noticed the query didn't filter it right so after I changed the curtime to new \DateTime('midnight') it was filtering correctly.

Upvotes: 0

Views: 113

Answers (1)

Dimitri Lavrenük
Dimitri Lavrenük

Reputation: 4879

When you use related models in a query as part of the matching or orderBy then the query will be build with joins to the related tables. That means, that the result is actually smaller and will not include appointments without customers.

The strange thing is that you see the last names when you debug it, otherwise i would assume that you have some configuration errors in the TCA. Can you provide the TCA code from the apointment table and may be its model?

Upvotes: 1

Related Questions