PATCH request replaces value in entity reference field instead of creating new

by Alvis   Last Updated August 10, 2018 10:07 AM

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

Tags : 8 json


Related Questions


How to use Icon8/webicons library with Drupal 7?

Updated May 04, 2016 08:03 AM

How to Logout a user using json?

Updated March 04, 2017 08:07 AM

Implementing schema.org

Updated May 18, 2017 17:07 PM

Disallow Json file in Drupal 7

Updated December 13, 2017 07:07 AM

How to return JSON data using Drupal 7

Updated August 22, 2015 17:03 PM