We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Since you are using an additional xPDO instance, you need to set the option for populating fields not defined in the schema for the object:

    $xpdo->setOption(xPDO::OPT_HYDRATE_ADHOC_FIELDS, true);


    This will allow the additional fields to be populated on the object and available from toArray().

    That said, you should define the relationship and use the Graph methods to more easily construct these kinds of queries and work with the related objects instead of just adding fields all, ad hoc like. smiley
      • 34004
      • 125 Posts
      SOLVED thanks to opengeek on IRC. Needed to hydrate fields. Code is now:

      
      $xpdo->setOption(xPDO::OPT_HYDRATE_ADHOC_FIELDS, true);
      $query = $xpdo->newQuery('ShopProducts');
      $query->select($xpdo->getSelectColumns('ShopProducts','ShopProducts',''));
      $query->leftJoin('DbFiles','DbFiles',array('ShopProducts.id = DbFiles.master_object_id'));
      $query->select($xpdo->getSelectColumns('DbFiles','DbFiles','DbFiles_'));
      $query->where(array(
          'ShopProducts.description:!=' => null,
          'ShopProducts.product_id:!=' => null
      
      ));
      $query->sortby('rand()');
      $query->limit(4);
      


      Glad that is solved! EDIT: I will work out how to do this properly, just stuck on this for a while and am glad that it's working.