从Varien_DB_Select加入中删除特定条件
-
28-09-2020 - |
题
我有一些连接的生成acodetagcode对象,我需要在其中一个中改变条件。我该怎么办?
更新:我发现“来自”部分中的条件,然后在“joincondition”部分中。我可以循环,但我不能把它们放回来
解决方案
所以这就是我想出的:
$fromAndJoins = $select->getPart(Zend_Db_Select::FROM);
foreach($fromAndJoins as $key=>$joins){
if(strpos($joins['joinCondition'],$attribute->getAttributeCode().'_idx.attribute_id')!==false){
$newcondition = //change $joins['joinCondition'] as you want
$fromAndJoins[$key]['joinCondition']=$newcondition;
}
}
$select->reset(Zend_Db_Select::FROM);
$select->setPart(Zend_Db_Select::FROM,$fromAndJoins);
. 其他提示
这是我将使用的方法。
您可以获得这样的条件(“其中”部分)如下:
$where = $collection->getSelect()->getPart('where');
.
然后,您可以循环通过这样的条件:
foreach ($where as $key => $condition)
{
// Do what you need
}
.
终于一旦您需要更改,请不要忘记将更新的条件应用于您的电切:
$collection->getSelect()->setPart('where', $where);
. 如果您收到错误
您无法以多次定义相关名称“xxx”>
您必须生成生成icotagcode项目,其中密钥在我的情况下
$key = $attribute->getAttributeCode().'_idx.attribute_id';
.