• How would I do this with xPDO?#

  • thingstodo Reply #1, 3 months, 3 weeks ago

    Reply

    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


  • Lucas Reply #2, 3 months, 3 weeks ago

    Reply
    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();
    }
    




  • thingstodo Reply #3, 3 months, 3 weeks ago

    Reply
    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