Saving field collections

i’d like to update an relation in a field collection - but somehow its not working correctly:

$user = DataObject\User::getById(2)

$fieldcollection = $user->getItemsF(); // get fieldcollection
$currentItem = $fieldcollection->get(0); // get item 0 from fieldcollection

$currentItem->setArray( $array ); // multiselect field -> gets saved - OK
$currentItem->setRelation( DataObject\Stuff::getById(6) ); // many-to-one relation -> won’t get saved

$user->save();

here’s the problem:
the array (multiselect-item) gets saved correctly.
unfortunately the many-to-one relation doesn’t change after saving… can’t null it or replace it with a new object…

any ideas?

@macmastermike Is there any class linked with that relational field? Is the object with ID=6 published?

hi
yes, the object is published.
i’ve just tried again with the current pimcore-demo and newest pimcore version (6.6.7).
here’s my quick test-code:

    $man = Manufacturer::getById(80);
    $fc = $man->getTestfc();

    $item0 = $fc->get(0);
    $item0->setInputtest("test 000"); // working and saved
    $item0->setManytoonetest(News::getById(766)); // updated in dump but not saved
    $item0->setManytomanytest([News::getById(766)]);  // updated in dump but not saved
    dump($item0);

    $item1 = $fc->get(1);
    $item1->setInputtest("test 111"); // working and saved
    $item1->setManytoonetest(News::getById(766));  // updated in dump but not saved
    $item1->setManytomanytest([News::getById(766)]);  // updated in dump but not saved
    dump($item1);

    $man->save();

in the backend you can see the result after reloading: fields are updated - relations not.

the dump after setting the relations looks good - and the right object is there.
just the saving doesn’t work… am i missing something? setting the relation somewhere else?

dump

bug reported https://github.com/pimcore/pimcore/issues/6733

fixed https://github.com/pimcore/pimcore/pull/6734 and will be available in v6.6.8