敏捷工具包-OR语句与模型结合 [英] Agile Toolkit - OR statement in combination with Model

查看:96
本文介绍了敏捷工具包-OR语句与模型结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型,我想从中选择调用方"或被调用方"是给定值的所有行,以便在网格中显示.

I have a Model from which I want to select all rows for which 'caller' or 'callee' is a given value for presentation in a Grid.

我尝试了许多不同的方法来实现这一目标,但是却一事无成.

I have tried lots of different avenues of accomplishing this and cannot get anywhere with it.

我在Grid上有一个工作过滤器,该过滤器按日期(开始和结束日期),状态("ANSWERED","NO_ANSWER")缩小了结果的范围,还可以为"caller"和"callee"添加条件,但是如何显示所有与'$ UserID'匹配的行呢?基本上显示用户参与的所有呼叫(行)?

I have a working filter on the Grid which narrows down the results by date (starting and ending dates), by status ("ANSWERED","NO_ANSWER"), I can also add conditions for 'caller' and 'callee', but how do I get it to show all rows where either 'caller' or 'callee' is a match to the current $UserID? Basically showing all calls (rows) a user was involved in?

MySQL查询本身是一个简单的OR构造,但是如何将其馈入"到模型或网格中,以使其与页面上的其他过滤器很好地配合?

The MySQL query itself is a simple OR construction, but how do I 'feed' it into the Model or the Grid so that it plays nicely with the other filters on the page?

推荐答案

您可以使用DSQL的orExpr()方法来生成所需的SQL.

You can use orExpr() method of DSQL to generate SQL for your needs.

例如,

$m = $this->model->debug();            // enable debug mode
$user_id = $this->api->auth->model->id;// currently logged in user ID
$q = $m->_dsql();                      // get models DSQL

$or = $q->orExpr();                    // initialize OR DSQL object
$or->where('caller', $user_id)         // where statements will be joined with OR
   ->where('callee', $user_id);

// use one of these below. see which one works better for you
$q->where($or);                        // add condition with OR statements
$q->having($or);                       // add condition with OR statements

当然,您可以将所有这些写得更短:

Of course you can write all of this shorter:

$m = $this->model->debug();            // enable debug mode
$user_id = $this->api->auth->model->id;// currently logged in user ID
$q = $m->_dsql();                      // get models DSQL

$q->where($q->orExpr()
    ->where('caller', $user_id)
    ->where('callee', $user_id)
);

这篇关于敏捷工具包-OR语句与模型结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆