Pimcore can’t set metadata for many-to-many relation

Hi,

I have a contact class that has an advanced many-to-many relation with the class named Etalissement.

This relation has some columns (Facturation, Livraison…)

The Classe relation definition and Object Relation Exemple:

In my code, I’m getting the contact by Email, The Etablissement by Path and creating the element metadata as follow:
> $contactObjet=DataObject\Contact::getByEmail($contactArr[“email”],1);

$referencedElement=DataObject\Etablissement::getByPath("/Folder/302238829-MonEtablissemet");
$references = [];
$elementMetadata = new DataObject\Data\ElementMetadata('metadata', ["facturation", "livraisons"], $referencedElement  );
$elementMetadata->setFacturation(true);
$references[] = $elementMetadata;
$contactObjet->setCompetence($references);
    $contactObjet->setPublished(true);
    $contactObjet->save();

However, the checkbox Facturation is not checked!

Can Someone Help!

Thanks in advance,

I think the first parameter should be the name of the relation parameter, in your case I think it is ‘competence’. So it should be:

$elementMetadata = new DataObject\Data\ElementMetadata('competence', ["facturation", "livraisons"], $referencedElement );

1 Like

it wotks! Thank you very much.

I used The field name used in Pimcore Documentation without changing it!

Thank you again!

it wotks! Thank you very much.

I used The field name used in Pimcore Documentation without changing it!

Thank you again!