使用Propel在Symfony中进行批量更新

时间:2012-12-27 15:00:40

标签: php join symfony-1.4 propel

当我的选择条件加入时,如何使用propel在symfony中进行批量更新?这是我想要做的一个例子。

$conn = Propel::getConnection(BudgetLinePeer::DATABASE_NAME);
// Create a Criteria object that will select the correct rows from the database
$selectCriteria = new Criteria();            
$selectCriteria->add(BudgetLinePeer::IDCOL1, $idcol1, Criteria::EQUAL);
$selectCriteria->addJoin(ProjectBudgetLinePeer::IDBUDGET_LINE, BudgetLinePeer::IDBUDGET_LINE);
$selectCriteria->add(ProjectBudgetLinePeer::IDCLIENT, $idclient, Criteria::EQUAL);
$selectCriteria->add(ProjectBudgetLinePeer::IDPROJECT, $project->getIdproject(), Criteria::EQUAL);
// Create a Criteria object includes the value you want to set
$updateCriteria = new Criteria();
$updateCriteria->add(BudgetLinePeer::STATUS, $status);
// Execute the query
BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);

我正在尝试在表BudgetLine中进行更新(更新新状态)。

编辑:以下是我收到的错误摘录:

  

为foreach()提供的参数无效   /Applications/MAMP/htdocs/proj_ict_new/trunk/cbm/plugins/sfPropelORMPlugin/lib/vendor/propel/runtime/lib/util/BasePeer.php   在第369行

这与join语句有关。我尝试使用useXYZQuery()->filterCon()->endUse()。但最终又出现了同样的错误。

1 个答案:

答案 0 :(得分:0)

我能够找到解决这个问题的另一种方法。这是解决方案:

$budgetLine_ids = BudgetLineQuery::create()
                 ->filterByIdcol1($col1)
                 ->useProjectBudgetLineQuery()
                 ->filterbyIdproject()->endUse()->find()->toArray('budgetline_id');

$selectCriteria = BudgetLineQuery::create()->filterByIdbudgetLine(array_keys($budgetLine_ids));      

// Create a Criteria object includes the value you want to set
$updateCriteria = new Criteria();
$updateCriteria->add(BudgetLinePeer::STATUS, $status);
// Execute the query
BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);