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

    I would like to create multiple objects in one query. I've a custom code where multiple objects are created and want to reduce the number of database calls.

    The piece of code looks like this:
    <?php
    // $objs = array with arrays with Object values
    foreach ($objs as $objValues) {
      $obj = $modx->newObject("Object");
      $obj->fromArray($objValues);
      $obj->save();
    }


    I prefer a piece of code like this (which creates one query instead of many):
    <?php
    $modx->newObjects("Object", $objs);


    Is this possible? I searched the modx forums, documentation, xpdo, internet but could not find anything.

    Thanks in advance!
    Huub
      I love flexibility