xpdo icon indicating copy to clipboard operation
xpdo copied to clipboard

updateCollection() ignores criteria

Open BobRay opened this issue 11 years ago • 2 comments

$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.

BobRay avatar Apr 02 '14 19:04 BobRay

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...

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

it should work as expected.

opengeek avatar Apr 02 '14 20:04 opengeek

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

rtripault avatar Apr 02 '14 21:04 rtripault