Replaces current references with references in the specified property.
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.
function replaceReferences(
collectionId: string,
propertyName: string,
referringItem: union,
referencedItem: union,
options: WixDataOptions,
): Promise<void>;
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.
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.
import wixData from "wix-data";
// ...
wixData
.replaceReferences("movies", "actors", "00001", "12345")
.then(() => {
console.log("References replaced");
})
.catch((error) => {
console.log(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.