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


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?

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

    $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


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?


bug reported

fixed and will be available in v6.6.8

I am working on Pimcore 6.2.3. I am facing the same issue.
Data is displaying in the Version tab but not in the Field collection Form tab.

I have applied Patch of mention 6 files but 2 files are not available due to version difference.

Any suggestions to make it work.
Thanks in advance.


@dvesh3 After applied patch and I have created two files in their respective path

  1. ManyToManyRelationTrait.php
  2. Version20200703093410.php
    I have executed migration manually by command. I am getting this error.

Please have a look and provide your suggestions.
Thanks in advance