2016-05-04 7 views
1

Ich habe in dieser Ausgabe der letzten zwei Tage festgefahren.Abfrage Filter zuweisen Unterabfrage zu einem Feld Wert

Bitte helfen.

Ich möchte die folgende Abfrage zuweisen.

$qr = "(select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = 'node' AND subconfigcode.deleted = '0') WHERE (((select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid))AND(((node.status = '1') AND (node.type IN ('offering'))))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0)"; 

zu

ein Feldwert Sicht.

Ich habe den folgenden Code verwendet.

function general_views_query_alter(&$view, &$query) { 
     $qr = " (select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = 'node' AND subconfigcode.deleted = '0') WHERE (((select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid))AND(((node.status = '1') AND (node.type IN ('offering'))))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0)"; 

     $query->add_where(1, "node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value", $qr); 

    } 

Aber es gibt folgende Abfrage zurück.

where node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value = '(select subconfigcode.field_subconfigcode_value AS configcode FROM node node LEFT JOIN field_data_field_select_parent_configuratio select_parent_configuratio ON node.nid = select_parent_configuratio.entity_id AND (select_parent_configuratio.entity_type = node AND select_parent_configuratio.deleted = 0) LEFT JOIN node select_parent_configuratio_node ON select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid LEFT JOIN field_data_field_subconfigcode subconfigcode ON select_parent_configuratio_node.nid = subconfigcode.entity_id AND (subconfigcode.entity_type = \'node\' AND subconfigcode.deleted = \'0\') WHERE (((select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid))AND(((node.status = \'1\') AND (node.type IN (\'offering\'))))) ORDER BY node.created DESC, configcode ASC LIMIT 1 OFFSET 0) ') 

Ich möchte Abfrage erhalten, ohne das Apostroph für Sub-Abfrage zugeordnet und entfernen Sie zusätzliche jedem Wert aufgeschlitzt hinzugefügt.

Bitte helfen.

Antwort

0

Antwort:

Direkte Abfrage ist nicht anwendbar für die Zuordnung Zweck im add_where Zustand.

Dafür habe ich das Abfrageobjekt mit generiert.

function general_views_query_alter(&$view, &$query) { 
        $subQuery = db_select('node', 'node'); $subQuery->leftJoin('field_data_field_select_parent_configuratio', 'select_parent_configuratio ', 'node.nid = select_parent_configuratio .entity_id'); 
        $subQuery->condition('select_parent_configuratio.entity_type', 'node', '='); 
        $subQuery->condition('select_parent_configuratio.deleted', '0', '='); 
        $subQuery->leftJoin('node', 'select_parent_configuratio_node', 'select_parent_configuratio.field_select_parent_configuratio_nid = select_parent_configuratio_node.nid'); 
        $subQuery->leftJoin('field_data_field_subconfigcode', 'subconfigcode', 'select_parent_configuratio_node.nid = subconfigcode.entity_id');  
        $subQuery->condition('subconfigcode.entity_type', 'node', '='); 
        $subQuery->condition('subconfigcode.deleted', '0', '='); 
        $subQuery->where("select_parent_configuratio.field_select_parent_configuratio_nid = node_field_data_field_select_parent_configuratio.nid"); 
        $subQuery->condition('node.status', "1", '='); 
        $subQuery->condition('node.type', array('offering'), 'IN'); 
        $subQuery->orderBy('configcode'); 
        $subQuery->addField('subconfigcode', 'field_subconfigcode_value', 'configcode'); 
        //$subQuery->range(0, 1); 
        $query->add_where($group,'node_field_data_field_select_parent_configuratio__field_data_field_subconfigcode.field_subconfigcode_value',$subQuery,'in'); 
} 

Mit diesem kann ich es die Abfrage und Zuordnung zu Wert der Variablen generieren.