Skip to content

How to set a relation to "null"? #66

@V-Orbit

Description

@V-Orbit

Hi @JaZo ! Just don't figure how to set a relation to null when saving a content which had a previous relation set.
Relation "publisher" is a hasOne relation

This is the attributes/relations array prior to hydration. this array works as expected.

$ordineAttributes = [
                    note => $datiForm['note'],
                    'totale_ordine' => $datiForm['totale_ordine'],
                    'stato' => [
                        'id' => base64_decode($datiForm['stato'])
                    ],

/* THIS IS THE RELATION I WANT TO EVENTUALLY SET TO NULL (OR SOMEWHAT SIMILAR) */
                    'publisher' => [
                         'id' => $datiForm['publisher']
                    ],

                    'cliente' => [
                        'id' => $datiForm['cliente_id']
                    ],
                    'righe_ordine' => $ids,
                ];

$itemOrdineDocument = $itemHydrator->hydrate(
                        $typeMapper->getMapping('node--ordini'), 
                        $ordineAttributes,
                        $orderID
                ); 

I already tried to:

  • pass an empty publisher array
  • pass publisher => null
  • pass "id" => "none"
  • pass "id" => "null"
  • pass "id" => null
  • pass "id" => 0

Of course, if I completely remove the publisher entry from the ordineAttributes array, the hydrator steps over and leaves the previous value unchanged.

What I'm doing wrong?

I also get errors when I do

$itemOrdineDocument->unsetRelation('publisher');
$ordineRepo->save($itemOrdineDocument);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions