Search.../

replaceReferences( )

Replaces current references with references in the specified property.

Description

The replaceReferences() function returns a Promise that resolves when the item's current references in the specified property are removed and references to the referenced items are added in their place. The Promise is rejected if the current user does not have update permissions for the collection.

Calling the replaceReferences() function does not trigger any hooks.

Note: The replaceReferences() function is not supported for Single Item Collections.

Syntax

function replaceReferences(collectionId: string, propertyName: string, referringItem: Object | string, referencedItem: Object | string | Array<Object> | Array<string>, [options: WixDataOptions]): Promise<void>

replaceReferences Parameters

NAME
TYPE
DESCRIPTION
collectionId
string

The ID of the collection that contains the referring item.

To find your collectionId, select the Databases tab in the Velo Sidebar. Hover over your collection, click the three dots, and select Edit Settings.

propertyName
string

The property to replaces the references in.

referringItem
Object | string

The referring item or referring item's ID.

referencedItem
Object | string | Array<Object> | Array<string>

The referenced item, referenced item's ID, an array of referenced items, or an array of referenced item IDs.

options
Optional
WixDataOptions

An object containing options to use when processing this operation.

Returns

Fulfilled - When the references have been inserted. Rejected - The error that caused the rejection.

Return Type:

Promise<void>

Was this helpful?

Replace a reference

This example replaces the references in the Actors field of the item in the Movies collection with the ID 00001 with a reference to the item with ID 12345.

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.replaceReferences("movies", "actors", "00001", "12345")
6 .then(() => {
7 console.log("References replaced");
8 })
9 .catch((error) => {
10 console.log(error);
11 });
12
Replace references using an array

This example replaces the references in the Actors field of the item in the Movies collection with the ID 00001 with references to the items with IDs 12345 and 67890.

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.replaceReferences("movies", "actors", "00001", ["12345", "67890"])
6 .then(() => {
7 console.log("References replaced");
8 })
9 .catch((error) => {
10 console.log(error);
11 });
12