---
title: Relationship update methods and their effects
description: When you create a relationship between two objects, the API request you use determines which scripts are triggered and when derived properties are recalculated.
component: pingoneaic
page_id: pingoneaic:idm-objects:object-relationship-update-differences
canonical_url: https://docs.pingidentity.com/pingoneaic/idm-objects/object-relationship-update-differences.html
keywords: ["Data Object Model", "Relationships"]
section_ids:
  update-the-source-object-directly: "Method 1: Update the source object directly"
  update-the-source-object-directly-effects: Effects
  update-the-source-object-relationship-endpoint: "Method 2: Update the source object's relationship endpoint"
  update-the-source-object-relationship-endpoint-effects: Effects
  update-the-target-object-relationship-endpoint: "Method 3: Update the target object's relationship endpoint"
  update-the-target-object-relationship-endpoint-effects: Effects
  update-the-target-object-directly: "Method 4: Update the target object directly"
  update-the-target-object-directly-effects: Effects
---

# Relationship update methods and their effects

When you [create a relationship](relationships.html) between two [objects](managed-objects.html), the API request you use determines which scripts are triggered and when derived properties are recalculated.

The following sections explain the effects of the four different ways you can update a relationship. For example, to create a relationship between a `planet` object and a `moon` object, you can either update the object directly or `POST` to the relationship endpoint. The method you choose has important implications for server-side processing.

## Method 1: Update the source object directly

You can create a relationship by sending a `PATCH` or `PUT` request to the "source" of the relationship. In this example, the `planet` object is the source.

Request

```none
PATCH managed/planet/saturn
[{ "operation" : "add", "field" : "/moons/-", "value" : { "_ref" : "managed/moon/titan" } }]

// Alternatively, a PUT request with the fully-updated moons array.
```

### Effects

* **Scripts on the source object (`planet`)**: The `field policy`, `onValidate`, and `onUpdate` scripts **are** invoked.\[[1](#_footnotedef_1 "View footnote.")]

* **Scripts on the target object (`moon`)**: Scripts aren't invoked.

* **RDVP calculations**: Recalculations for relationship derived virtual properties (RDVPs) on the target object (`moon`) depend on notification settings. If a recalculation is triggered, the `moon` object's `field policy`, `onValidate`, and `onUpdate` scripts are then invoked.

## Method 2: Update the source object's relationship endpoint

You can also create the relationship by sending a `POST` request to the relationship endpoint on the source object.

Request

```none
POST managed/planet/saturn/moons?_action=create
{ "_ref" : "managed/moon/titan" }
```

### Effects

* **Scripts on the source object (`planet`)**: Scripts aren't invoked.

* **Scripts on the target object (`moon`)**: Scripts aren't invoked.

* **RDVP calculations**: RDVP calculations aren't triggered on either object.

## Method 3: Update the target object's relationship endpoint

Similarly, you can `POST` to the relationship endpoint on the target object.

Request

```none
POST managed/moon/titan/planet?_action=create
{ "_ref" : "managed/planet/saturn" }
```

### Effects

* **Scripts on the source object (`planet`)**: Scripts aren't invoked.

* **Scripts on the target object (`moon`)**: Scripts aren't invoked.

* **RDVP calculations**: RDVP calculations aren't triggered on either object.

## Method 4: Update the target object directly

Finally, you can create the relationship by sending a `PATCH` or `PUT` request to the "target" of the relationship.

Request

```none
PATCH managed/moon/titan
[{ "operation" : "add", "field" : "/planet/-", "value" : { "_ref" : "managed/planet/saturn" } }]

// Alternatively, a PUT request with the fully-updated planets array.
```

### Effects

* **Scripts on the source object (`planet`)**: Scripts aren't invoked.

* **Scripts on the target object (`moon`)**: The `field policy`, `onValidate`, and `onUpdate` scripts **are** invoked.\[[1](#_footnotedef_1 "View footnote.")]

* **RDVP calculations**: Recalculations for RDVPs on the source object (`planet`) depend on notification settings. If a recalculation is triggered, the `planet` object's `field policy`, `onValidate`, and `onUpdate` scripts are then invoked.

***

[1](#_footnoteref_1). The object state in these scripts doesn't show the new relationship because it hasn't been persisted yet. However, \`postUpdate\` and \`postCreate\` script hooks do have the new and old relationship states available.
