processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

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

Open adrianbj opened 6 months ago

adrianbj commented 6 months ago

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.