I plan to list all polls in the most recent order where I need to join my "poll" table with the "node" table and display them with pager. Here is what I do:
$polls_query = db_select('poll', 'p')
->extend('PagerDefault')
->limit(3);
$polls_query->join('node', 'n', 'n.nid = p.nid')
->fields('p', array('nid'))
->condition('p.active', 1, '=')
->orderBy('n.created', 'DESC');
$result = $polls_query->execute();
foreach ($result AS $poll) {
$polls[] = array('data' => drupal_render(node_view(node_load($poll->nid), 'teaser')));
}
$content['pager_list'] = array(
'#theme' => 'item_list',
'#items' => $polls,
'#title' => t('Listing Consensus'),
'#type' => 'ul',
);
$content['pager_pager'] = array('#theme' => 'pager');
return drupal_render($content);
Unfortunately I see a white screen of death and the php error log says "PHP Fatal error: Call to a member function fields() on a non-object in .. " and thats the line where I mention after fields. If I dont use join, everything works fine.
If anyone else has had similar problems, please share the solution.