Mysql
 sql >> Database >  >> RDS >> Mysql

clausole condizionali drupal sql per più tabelle?

Non puoi concatenare leftJoin (o qualsiasi join ) nelle query Drupal, perché leftJoin() restituisce l'alias, non la query. Quindi dovresti usare execute() per "eseguire" la query.

$or = db_or()
  ->condition('fd.field_detailed_question_value', '%'.db_like($term ).'%', 'LIKE')
  ->condition('fb.body_value','%'.db_like($term ).'%' , 'LIKE');

$query = db_select('node', 'n');
$query->fields('n');
$query->leftJoin('field_data_body' , 'fb', 'fb.entity_id=n.nid');
$query->leftJoin('field_data_field_detailed_question' ,'fd', 'fd.entity_id=n.nid');
$query->condition($or);
$stmt = $query->execute(); // execute the query (returns the "statement" to fetch).

while ($row = $stmt->fetchObject()) {
    //..
}

Devi aggiungere campi :

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

o

$query = db_select('node', 'n')
         ->addField('n','title')
         ->addField('n','nid');