2

我有一个如下所示的 extbase 数据库查询。

$query = $this->createQuery();        
$result = $query->statement("Select * FROM table1 WHERE hidden = 0 AND deleted = 0 AND (".$PublicationYears.") AND logo != '' ORDER BY uid ASC LIMIT 0, ".$iLimit." ")->execute();             
return $result;


$PublicationYears = "ttra = '12' or ttra = '13' or ttra = '14'";

我将此查询转换如下,

$query = $this->createQuery();

$query->getQuerySettings()->setRespectStoragePage(FALSE);

$query->matching( $query->logicalAnd(
       $query->equals('deleted', 0),
       $query->equals('hidden', 0)
    ));

$query->matching($query->logicalAnd($PublicationYears));

$query->matching($query->logicalNot(
     $query->equals('logo', '')
 ));

$query->setOrderings(array('uid' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));

$query->setLimit((integer)$iLimit);
$Result = $query->execute();

return $Result;

但结果查询不包含与以下相关的查询部分,

$query->matching($query->logicalAnd($PublicationYears));

我认为上述查询中还有其他错误。

请帮助我创建正确的查询。

提前致谢。

4

2 回答 2

9

首先你不需要这个

$query->matching( $query->logicalAnd(
   $query->equals('deleted', 0),
   $query->equals('hidden', 0)
));

disable fields根据 ext_tables.php 中的表设置,默认包含在查询中

多重匹配将不起作用导致您的第三次匹配

$query->matching($query->logicalNot(
 $query->equals('logo', '')
 ));

是在字符串上覆盖matching()之前使用 的吗?logicalAnd它也不起作用

在你的情况下,你只需要把所有东西都放进去logicalAnd,像这样

$constraints = array();
$subConstraints = array();
$subConstraints[] = $query->equals('ttra', 12);
$subConstraints[] = $query->equals('ttra', 13); 
$subConstraints[] = $query->equals('ttra', 14);
$constraints[] = $query->logicalOr($subConstraints);
$constraints[] = $query->logicalNot(
     $query->equals('logo', '')
 ));

$query->matching($query->logicalAnd($constraints));
于 2015-05-16T17:48:57.993 回答
0

对于您的 PublicationYears 值,您必须进行如下匹配或查询:我认为它可能仅适用于 PublicationYears 变量。

 $query->matching($query->logicalAnd(
            $query->logicalOr(
                $query->equals('ttra', 12)           
            ),
            $query->logicalOr(
                $query->equals('ttra', 13)           
            ),
            $query->logicalOr(
                $query->equals('ttra', 14)           
            ),
        ));
于 2016-11-15T06:25:42.103 回答