We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36572
    • 20 Posts
    I have the following Class. If i don't add the SELECT in the prepareQueryAfterCount();
    I get the normal data for mpcOrder. When i add the Add i get no data add all.

    What am i doing wrong?

    I did get collection within prepareQueryAfterCount-method and got the correct data.

    I have the idea he doesn't reach the prepareRow at all. Is there are work around?


    class mpcOrderGetListProcessor extends mpcObjectGetListProcessor {
    
      public $classKey = 'mpcOrder';
      public $languageTopics = array();
      public $defaultSortField = 'docnumber';
      public $defaultSortDirection = 'ASC';
      public $objectType = 'mpcOrder';
      public $cacheFolder = 'mpcOrder';
    
      /**
       * @param xPDOQuery $c
       * @return \xPDOQuery
       */
      public function prepareQueryBeforeCount(xPDOQuery $c) {
    
        $where = $this->getProperty('where');
    
        $c->leftJoin('mpcOrderLines', 'mpcOrderLines', array('`mpcOrder`.`docnum` =`mpcOrderLines`.`docnum`'));
        $c->where(array('mpcOrderLines.deliverystatus' => 1));
        if (!empty($where)) {
          $where = json_decode($where, true);
          if (is_array($where)) {
            foreach ($where as $wkey => $wsearch) {
              $c->where(array($wkey => $wsearch));
            }
          }
        }
    
        return $c;
      }
    
      public function prepareRow(xPDOObject $object){
    	  $ta = $object->toArray('',false,true);
    	  return $ta;
      }
    
      public function prepareQueryAfterCount(xPDOQuery $c) {
    
        $c->select($this->modx->getSelectColumns('mpcOrder', 'mpcOrder'));
        $c->select($this->modx->getSelectColumns('mpcOrderLines', 'mpcOrderLines'));
        return $c;
      }
    
    }
    
    return 'mpcOrderGetListProcessor';
    


    This question has been answered by sterce-friso. See the first response.

    [ed. note: sterce-friso last edited this post 12 years, 7 months ago.]
      Developer @ Sterc bureau voor internet & marketing
      • 4172
      • 5,888 Posts
      seems you have some same column-names in both tables.
      Try to prefix the columns for one of them:

      $c->select($this->modx->getSelectColumns('mpcOrderLines', 'mpcOrderLines','Lines_'));


      And I think, its better to add the select before counting.

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
      • discuss.answer
        • 36572
        • 20 Posts
        Hi Bruno,

        Thanks for the reply.

        My colleague found the issue. The order by statement was incorrect. (Oeps laugh )
          Developer @ Sterc bureau voor internet & marketing