2016-05-04 17 views
1

私は過去2日間この問題を抱えています。クエリフィルタは1つのフィールド値にサブクエリを割り当てます

助けてください。

次のクエリを割り当てたいと思います。

$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)"; 

つのビューのフィールド値

へ。

私は以下のコードを使用しました。

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); 

    } 

ただし、クエリの次の部分が返されます。

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) ') 

私は、サブクエリのために割り当てられた単一引用符なしでクエリを取得し、余分なを削除するには、各値に加え引き下げ。

助けてください。

答えて

0

回答:

直接クエリがadd_where条件の代入目的には適用されません。

そのために、私はクエリオブジェクトを使用して生成しました。

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'); 
} 

これを使用して、変数の値にクエリと割り当てを生成できます。

関連する問題