Last Updated: February 25, 2016
·
1.033K
· sanguis

Drupal 7 dB abstraction layer pager rendering

when using db_select() and the desired result is to have a pager output the extend('PagerDefault') and limit(30); functions must be part of the original class declaration.

$topics = db_select('taxonomy_term_data', 'ttd')
->extend('PagerDefault')
->limit(30);
$topics->fields('ttd', array('tid', 'name'))
->orderBy('n.changed', 'DESC')
->condition('ttd.vid', 3)
->distinct();
$topics->innerJoin('field_data_field_tax_special_topic', 'sp', 'ttd.tid = field_tax_special_topic_tid');
$topics->leftJoin('node', 'n', 'n.nid = sp.entity_id');
$result = $topics->execute();

Would Work

While

$topics = db_select('taxonomy_term_data', 'ttd');
$topics->fields('ttd', array('tid', 'name'))
->extend('PagerDefault')
->limit(30)
->orderBy('n.changed', 'DESC')
->condition('ttd.vid', 3)
->distinct();
$topics->innerJoin('field_data_field_tax_special_topic', 'sp', 'ttd.tid = field_tax_special_topic_tid');
$topics->leftJoin('node', 'n', 'n.nid = sp.entity_id');
$result = $topics->execute();

would not