1

我正在尝试向查询添加条件,例如:

civicrm_contact_civicrm_relationship.id <> civicrm_contact_civicrm_relationship_1.id

但是对于第二个字段,drupal 将它作为一个字符串,所以它总是导致

civicrm_contact_civicrm_relationship.id <> 'civicrm_contact_civicrm_relationship_1.id'

我尝试使用数值但没有成功。

知道我该怎么做吗?可能是另一个钩子?欢迎任何提示!

我的代码:

        $view->query->where[2]["conditions"][0]["field"] = "civicrm_contact_civicrm_relationship_1.id";
        $view->query->where[2]["conditions"][0]["operator"] = "IS NULL";
        $view->query->where[2]["conditions"][0]["value"] = "";

        $view->query->where[2]["conditions"][1]["field"] = "civicrm_contact_civicrm_relationship.id";
        $view->query->where[2]["conditions"][1]["operator"] = "IS NULL";
        $view->query->where[2]["conditions"][1]["value"] = "";

        $view->query->where[2]["conditions"][2]["field"] = "civicrm_contact_civicrm_relationship.id";
        $view->query->where[2]["conditions"][2]["value"] ="civicrm_contact_civicrm_relationship_1.id";
        $view->query->where[2]["conditions"][2]["numeric"] = "1";
        $view->query->where[2]["conditions"][2]["operator"] = "<>";

        $view->query->where[2]["type"] = "OR";
4

1 回答 1

3

尝试类似的东西

    函数 my_hook_views_query_alter(&$view, &$query)
    {
      if ($view->name == 'my_hook') {
        $alias = $query->add_table('civicrm_contact_civicrm_relationship','civicrm_contact_civicrm_relationship_1');
        $query->add_where_expression(0,'civicrm_contact_civicrm_relationship.id <> civicrm_contact_civicrm_relationship_1.id');
        dpm($查询); //使用开发模块将对象转储给管理员
      }
    }
    

于 2013-06-16T07:35:44.320 回答