We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37099
    • 338 Posts

    How would I do this with xPDO?

    $table = $modx->getFullTableName('products');
    $result = $modx->db->update( " field1 = '$field1', field2 = '$field2'  " , $table, "parent=$parent" );
    


    Would I need to use getCollection then loop through the results, or is there a simpler method?

    Thanks
    Mike
      • 33968
      • 863 Posts
      Have you created an xPDO model (schema, class, etc) for your 'products' table?

      If so, doing this would be achievable as follows:
      $products = $modx->getIterator('products', array('parent' => $parent));
      
      foreach ($products as $product) {
          $product->set('field1', $field1);
          $product->set('field2', $field2);
          $product->save();
      }
      


        • 37099
        • 338 Posts
        Yes, the models all set up.

        It seems the price of using xPDO is a big processing overhead, for a quite straight forward sql update, and extra lines of code.

        What is the advantage of doing it the xPDO way in this instance?

        Cheers
        Mike