Layinka
Layinka

Reputation: 415

Drupal8 EntityQuery failing on sort

I am currently using the Entityquery API in Drupal8. I have some code that fails whenever I try to sort, but which works if I remove the sort line. I have checked the log and I cannot see anything about the error in the log.

See below.

This works:

$query->condition('status', 1)
  ->condition('type', 'programme')      
  ->range(0,5);

This Doesn't

$query->condition('status', 1)
  ->condition('type', 'programme')
  ->sort('changed', 'DESC')
  ->range(0,5);

Please can someone tell me what is going on?

Upvotes: 0

Views: 1397

Answers (1)

guanxiaohua2k6
guanxiaohua2k6

Reputation: 371

I wrote some similar code before. It seems that there is no problem in your code. One thing that you maybe forgot, is the "execute()" method should be called at last. So the code will be like the followings.

$query->condition('status', 1)
  ->condition('type', 'programme')
  ->sort('changed', 'DESC')
  ->range(0,5)
  ->execute();

Upvotes: 0

Related Questions