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

    I’ve written a part of code to delete many records:
    		if ($this->post) {
    			foreach ($this->post['firms'] as $f) {
    				$firm = $this->modx->getObject('klimaFirma',$f);
    				$firm->remove();
    			}
    		}
    


    but as I can see it only deletes 1 row.
    How should code for removing many rows look like?

    --
    Regards
    MM
      • 22303 MODX Staff
      • 10,725 Posts
      You can xPDOObject::remove() individual objects that way, though it’s more efficient to use xPDO::removeCollection(). However, your code should work as long as $this->post[’firms’] is an array with multiple valid values for the primary key of klimaFirma.
        • 17838
        • 82 Posts
        Thank you for removeCollection() tip.

        Code with remove() works, I’ve just got some redirect in a loop.

        sorry