isReferenced( )
Checks if a reference to the referenced item exists in the specified property of the referring item.
Description
The isReferenced()
function returns a Promise that resolves to true
if
the referring item contains a reference to the referenced item in the
specified property. The Promise is rejected if the current
user does not have read permissions for the collection.
Calling the isReferenced()
function does not trigger any hooks.
Note: The
isReferenced()
function is not supported for Single Item Collections.
Syntax
function isReferenced(collectionId: string, propertyName: string, referringItem: Object | string, referencedItem: Object | string, [options: WixDataOptions]): Promise<boolean>
isReferenced 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 that possibly contains the references to the referenced item.
The referring item or referring item's ID.
The referenced item or referenced item's ID.
An object containing options to use when processing this operation.
Returns
Fulfilled - Whether the referring item contains a reference to the referenced item or not. Rejected - The error that caused the rejection.
Return Type:
Was this helpful?
Get referenced items
This example checks if the item in the Movies collection with the ID 00001 has a reference in its Actors field that refers to an item with the ID 12345.
1import wixData from 'wix-data';23// ...45wixData.isReferenced("movies", "actors", "00001", "12345")6 .then((result) => {7 let isReferenced = result; // true8 })9 .catch((err) => {10 let errorMsg = err;11 });12