【问题标题】:symfony 1.4 propel combine two AND in scopes with OR in where clausesymfony 1.4推进将两个AND在范围内与OR在where子句中
【发布时间】:2016-09-27 18:32:57
【问题描述】:

我正在使用推进器在 Symfony 1.4 上重新编码网站,并且从一个多小时开始,我正在搜索如何使用推进器来做到这一点? (在 Symfony 1.4 上推进 1.4)

SELECT * FROM 'test' WHERE ( var_1 = 1 AND var_2 = 2) OR ( var_1 = 2 AND var_2 = 1)

我正在尝试使用此代码

$c = new Criteria();
$c->add(MessagesPeer::USER_FROM, $user->getId(), Criteria::EQUAL);
$c->addAnd(MessagesPeer::USER_TO, $this->user_id, Criteria::EQUAL);
$c->addOr(MessagesPeer::USER_FROM, $this->user_id, Criteria::EQUAL);
$c->add(MessagesPeer::USER_TO, $user->getId(), Criteria::EQUAL);

但结果是这样的:

WHERE (messages.USER_FROM=16405 OR messages.USER_FROM=56) AND messages.USER_TO=16405

有什么建议吗?

【问题讨论】:

    标签: symfony-1.4 propel


    【解决方案1】:

    您的 Propel 版本已经过时了。我强烈建议您将 Propel 至少升级到 1.5,该版本比 6 years ago 更高。

    使用 v1.5+,您将使用新的 Query 类,如下所示:

    $messages = MessagesQuery::create()
        ->condition('cond1', 'Messages.UserFrom = ?', $user->getId())
        ->condition('cond2', 'Messages.UserTo = ?', $this->user_id)
        ->combine(['cond1', 'cond2'], 'and', 'cond12')
        ->condition('cond3', 'Messages.UserFrom = ?', $this->user_id)
        ->condition('cond4', 'Messages.UserTo = ?', $user->getId())
        ->combine(['cond3', 'cond4'], 'and', 'cond34')
        ->where(['cond12', 'cond34'], 'or')
        ->find();
    

    使用条件见PropelRelational API documentation。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      相关资源
      最近更新 更多