PHP error 500 when including a left join on a pager query in db_select() I've got a query which is causing a PHP error 500 whenever I add a left join:


  PHP Fatal error:  Call to a member function orderBy() on a non-object


Here's the query:

$query = db_select('my_table', 'mt')
         -&gt;extend('PagerDefault')
         -&gt;fields('mt')
         -&gt;fields('u', array('name')
         -&gt;leftJoin('users', 'u', 'u.uid = mt.user_id')
         -&gt;orderBy('mt.my_table_id', 'DESC')
         -&gt;limit($results_per_page);

$result = $query-&gt;execute();


The query is to be used with a table + pager. If I remove the jeftJoin() and respective fields() the query works perfectly. Can anyone shed some light as to why this might be happening?

Many thanks
The documentation says:


  Joins cannot be chained, so they have to be called separately (see Chaining). If you are chaining multiple functions together do it like this:

$query = db_select('node', 'n');
$query-&gt;join('field_data_body', 'b', 'n.nid = b.entity_id');
$query
  -&gt;fields('n', array('nid', 'title'))
  -&gt;condition('n.type', 'page')
  -&gt;condition('n.status', '1')
  -&gt;orderBy('n.created', 'DESC')
  -&gt;addTag('node_access');