I have an entity reference field named order_entryin my crm core individual, the problem is that when I try to PATCHthe user and send new order there, it replaces the order instead of adding new reference field. There can be many orders belonging to the same individual. Here is what I encode and send:

$inp = array(
    '_links' => array(
      'self' => array(
        'href' => $url.'/crm-core/individual/6?_format=hal_json'
      ),
      'type' => array(
        'href' => $url.'/rest/type/crm_core_individual/tilitysasiakas',
      ),
      $url.'/rest/relation/crm_core_individual/tilitysasiakas/field_order_entry' => array(
        array(
            'href' => $url.'/order/86?_format=hal_json'
        )
      )
    ),
    'type' => array(
      array(
        'target_id' => 'tilitysasiakas',
      )
    ),
    '_embedded' => array(
        $url.'/rest/relation/crm_core_individual/tilitysasiakas/field_order_entry' => 
        array(
          array(
            '_links' => array(
              'self' => array(
                'href' => $url.'/order/86?_format=hal_json',
              ),
              'type' => array(
                'href' => $url.'/rest/type/node/order_entry',
              )
            ),
            'uuid' => array(
              array(
                'value' => 'uuid of order entry here',
              )
            )
          )
        )
      )
    );

Edit: I would like to know if the array I am sending is correct or should the order_entry field be sent in some other form so that existing orders would not disappear

  • Hey Alvis, welcome to Drupal Answers! What is your actual question? Can you rewrite your post in a way that it makes it a question? As it now seems a little bit unclear what exactly you want. – leymannx Aug 10 at 9:30
  • As far as I remember, PATCH in D8's entity resource API works at the field level; you can only replace the entire field value. – Christoph Burschka Aug 10 at 11:14

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.