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
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.
The property to replaces the references in.
The referring item or referring item's ID.
The referenced item, referenced item's ID, an array of referenced items, or an array of referenced item IDs.
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:
Was this helpful?
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.
1import wixData from 'wix-data';23// ...45wixData.replaceReferences("movies", "actors", "00001", "12345")6 .then(() => {7 console.log("References replaced");8 })9 .catch((error) => {10 console.log(error);11 });12
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.
1import wixData from 'wix-data';23// ...45wixData.replaceReferences("movies", "actors", "00001", ["12345", "67890"])6 .then(() => {7 console.log("References replaced");8 })9 .catch((error) => {10 console.log(error);11 });12