douna2014 2015-04-11 22:06
浏览 20
已采纳

Modx xPDO getMany没有返回预期的结果

I'm not sure what is going on here, but I'm trying to retrieve some budgets from a modx/xpdo object and getting unexpected results. From the code below, both foreach loops return the same results [that of the first getMany call. 2 items] if I switch the order of the getmany calls I get only one result for both foreach loops.

$tipa = $this->modx->getObject('Tipa', array('id' => $id, 'token' => $token));


// should retrieve two objects
$tipa_sub_budgets = $tipa->getMany('TipaBudget', array('budget_type_id:!=' => '999'));
foreach($tipa_sub_budgets as $sb){
    echo $sb->get('id');
}

// should retrieve one object
$tipa_primary_budgets = $tipa->getMany('TipaBudget', array('budget_type_id' => '999'));
foreach($tipa_primary_budgets as $tb){
    echo $tb->get('id');
}

I'm not sure what is happening here. What is the correct way to grab 2 sets of objects from the $tipa object?

  • 写回答

1条回答 默认 最新

  • dongshan4878 2015-04-12 01:27
    关注

    I think whereas xPDO::getObject() can be passed the criteria either as an array or an instance of xPDOCriteria, xPDOObject::getMany() expects only an instance of xPDOCriteria meaning the array will not work.

    Try passing an instance of xPDOCriteria like so...

    $criteria = $this->modx->newQuery("TipdaBudget"); // classname, not the alias
    $criteria->where(array("budget_type_id:!=" => 999));
    
    $tipa_sub_budgets = $tipa->getMany("TipaBudget", $criteria);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改