douzepao0281 2012-04-13 20:21
浏览 41

在Propel ORM中加入左连接的递归问题

With Propel ORM (1.6.5), when I joinWith() a table "A" to table "B" and then later call toArray() on the result PropelObjectCollection, the entry for B in each A record contains all the records for A again (see dump below).

A is LEFT JOINd to B. Each record in A points to exactly one in B. Code I am using:

$oAQuery = AQuery::create()
  ->joinB('b', Criteria::LEFT_JOIN)
    ->useBQuery()
        ->_if(strlen($sB))
          ->filterByBField1(str_replace(' ', '%', $sCity))
        ->_endif()
      ->endUse()
  ->with('b');

$oCollection = $oAQuery->find();
$aArray = $oAQuery->toArray();

toArray() dump:

Array
(
    [0] => Array
        (
            [Field1] => 29
            [Field2] => 0
            [B] => Array
                (
                    [BField1] => 7
                    [BField2] => 10
                    [As] => Array
                        (
                            [A_0] => *RECURSION*
                            [A_1] => Array
                                (
                                    [Field1] = 234
                                    [Field2] = 3424
                                    ...

I want to stop this, primarily, because there are many records and with the recursion I easily go over a 512m memory_limit for PHP (i even did 2048m for a test, still went over)

  • 写回答

1条回答 默认 最新

  • dongshan1036 2012-06-25 09:02
    关注

    You can write your own formatter, so that you can decide what to do with the result set: http://www.propelorm.org/reference/model-criteria.html#using_an_alternative_formatter.

    Using a custom formatter requires an extra method call:

    $aArray = $oAQuery->setFormatter('MyCustomFormatter')->find();
    // instead of $aArray = $oAQuery->toArray();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow