updateCollection() ignores criteria #34

BobRay opened this Issue Apr 2, 2014 · 2 comments


None yet

3 participants

BobRay commented Apr 2, 2014

$c = $modx->newQuery('modResource');
$c->where(array('class_key' => 'modDocument'));
$modx->updateCollection('modResource', array('class_key' => 'extResource'), $c);

This code should update only resources with class_key set to 'modDocument'.

It updates every resource for me - a not easily reversible disaster. ;)

The count using $c with getCollection() is correct, so the problem is not with the criteria.
Adding $c->prepare() is no help.

opengeek commented Apr 2, 2014

Unfortunately, updateCollection() only works with an array of criteria at the moment, and not with an xPDOQuery instance as you might expect.

If you reworked that as...

    array('class_key' => 'extResource'), 
    array('class_key' => 'modDocument')

it should work as expected.


Might worth updating the PHPDoc then.
I assume the same goes for removeCollection, right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment