drupal basic sql query

darren-w-
darren-w- used Ask the Experts™
on
Hi, Please could someone help

This is my call:

  
function zendcalender_data() {
  $query = db_select('node', 'n')
      ->fields('n', array('nid', 'title', 'created'))
      ->leftJoin('field_data_field_event_date', 'fed', "(fed.entity_id = n.nid AND fed.entity_type = node AND fed.deleted = 0)")
      ->condition('status', 1)
      ->orderBy('created', 'DESC'); 
  $query->execute();


  return $query;
}

Open in new window


In drush I'm just running a simple php script with print_r using the php-script command on the returned data and I'm getting this error.
...
Drush command terminated abnormally due to an unrecoverable error.                                             Error: Call to a member function condition() on a non-object in... line (the one with orderBy above)

Whats going on?

Thanks  Darren
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Leon TealeSenior Penetration Tester

Commented:
you might need this patch:

http://drupal.org/node/1719370

Author

Commented:
Dont think this is it, running  7.17 that was only updated a few weeks back
Technical Lead
Commented:
your function has to be like this

function zendcalender_data() {
  $query = db_select('node', 'n');
      $query->fields('n', array('nid', 'title', 'created'));
      $query->leftJoin('field_data_field_event_date', 'fed', "(fed.entity_id = n.nid AND fed.entity_type = node AND fed.deleted = 0)");
      $query->condition('status', 1)
      ->orderBy('created', 'DESC');
  $query->execute();


  return $query;
}
Whenever you use join in D7, you have the split the query like this..

Author

Commented:
needed to add fetchAll() to call to get results

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial