processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

Inability to directly set and save changes to multi-value page reference field via a string of IDs

Open adrianbj opened this issue 1 year ago • 0 comments

Short description of the issue

$page->of(false);
$page->field_name = '1234|1235';
$page->save('field_name');

won't overwrite existing entries for the field - the newly set values will be appended to existing ones. You need to do:

$page->of(false);
$page->field_name = null;
$page->field_name = '1234|1235';
$page->save('field_name');

or

$page->set('field_name', null);
$page->setAndSave('field_name', '1234|1235');

Expected behavior

Setting the field explicitly, rather than ->remove() and ->add() should remove all existing entries and replace with provided IDs.

Actual behavior

Existing selected page IDs are not automatically removed.

adrianbj avatar Mar 22 '24 02:03 adrianbj