5

My query return me an error. I have the gid of a organic group. I want to retrieve the last news for this group.

 $query = db_select('node','n');
 $result = $query
 ->fields('n')
 ->condition('type','news','=')
 ->join('field_data_group_audience','fdga','n.nid = fdga.entity_id AND fdga.group_audience_gid = :gid', array(':gid' => $gid))
 ->execute();

This query give me a : Fatal error: Call to a member function execute() on a non-object

Thanks

7

The join() method doesn't return the query object, so can't be used in a chain like you're currently doing. You'll need to do something like this instead:

$query = db_select('node','n');
  ->fields('n')
  ->condition('type','news','=');

$query->join('field_data_group_audience','fdga','n.nid = fdga.entity_id AND fdga.group_audience_gid = :gid', array(':gid' => $gid));

$result = $query->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.