CorvidReference

WixDataQueryReferencedResult

The results of a data reference query, containing the retrieved items.

When you execute a reference query with the queryReferenced() function, it returns a Promise that resolves to a WixDataQueryReferencedResult object. This object contains the items that match the reference query and functions for paging through the query results.

Table of Contents

PROPERTIES

?
Store values associated with an object.
itemsReturns the items that match the reference query.
totalCountReturns the total number of items that match the reference query.

FUNCTIONS

?
Perform actions on an object.
hasNext( )Indicates if the reference query has more results.
hasPrev( )Indicates if the reference query has previous results.
next( )Retrieves the next page of reference query results.
prev( )Retrieves the previous page of reference query results.

items

Returns the items that match the reference query.

Description

The current page of items retrieved by the reference query.

The page size is 50 items. Navigate through pages of items with the prev() and next() functions.

When no items match the reference query, the items array is empty.

Syntax

get items(): Array<Object>
TYPE
?
The kind of data the property stores.
Array<Object>

Examples

Get the items of a reference query result

let items = results.items;

/*
 * [
 *   {
 *     "_id":          "1234",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-29T08:35:52.344Z",
 *     "_updatedDate": "2017-05-29T08:35:52.344Z",
 *     "first_name":   "Jane",
 *     "last_name":    "Doe"
 *   },
 *   {
 *     "_id":          "5678",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-25T12:48:56.572Z",
 *     "_updatedDate": "2017-05-29T07:30:15.869Z",
 *     "first_name":   "John",
 *     "last_name":    "Doe"
 *   }
 * ]
 */

Perform a reference query and get the items of the result

import wixData from 'wix-data';

// ...

wixData.queryReferenced("movies", "00001", "actors")
  .then( (results) => {
    if(results.items.length > 0) {
      let items = results.items; // see below
    } else {
      // handle case where no matching items found
    }
  } ) ;

/* items:
 *
 * [
 *   {
 *     "_id":          "1234",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-29T08:35:52.344Z",
 *     "_updatedDate": "2017-05-29T08:35:52.344Z",
 *     "first_name":   "Jane",
 *     "last_name":    "Doe"
 *   },
 *   {
 *     "_id":          "5678",
 *     "_owner":       "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",
 *     "_createdDate": "2017-05-25T12:48:56.572Z",
 *     "_updatedDate": "2017-05-29T07:30:15.869Z",
 *     "first_name":   "John",
 *     "last_name":    "Doe"
 *   }
 * ]
 */

totalCount

Returns the total number of items that match the reference query.

Description

The totalCount returns the total number of items that match the reference query, not just the number of items in the current page.

Syntax

get totalCount(): number
TYPE
?
The kind of data the property stores.
number

Examples

Get the length of a reference query result

let resultCount = results.totalCount; // 150

Perform a reference query and get the length of the result

import wixData from 'wix-data';

// ...

wixData.queryReferenced("movies", "00001", "actors")
  .then( (results) => {
    let resultCount = results.totalCount; // 150
  } ) ;

hasNext( )

Indicates if the reference query has more results.

Syntax

function hasNext(): boolean
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
boolean
true if there are more results.

Examples

Get whether the reference query result object has more results

let hasNext = results.hasNext(); // true

hasPrev( )

Indicates if the reference query has previous results.

Syntax

function hasPrev(): boolean
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
boolean
true if there are previous results.

Examples

Get whether the reference query result object has previous results

let hasPrev = results.hasPrev(); // false

next( )

Retrieves the next page of reference query results.

Description

The next() function retrieves the next page of reference query results.

The page size is 50 items. Navigate through pages of items with the prev() and next() functions.

If items are added or removed between calls to next() the values returned may change.

Syntax

function next(): Promise<WixDataQueryReferencedResult>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.

Fulfilled - A reference query result object with the next page of query results. Rejected - The errors that caused the rejection.

Examples

Get the next page of a query result

oldResults.next()
  .then( (results) => {
    let newResults = results;
    let items = newResults.items;
    let firstItem = items[0];
    let totalCount = newResults.totalCount;
    let hasNext = newResults.hasNext();
    let hasPrev = newResults.hasPrev();
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Iterate through all pages of reference query results

let results = await wixData.queryReferenced("movies", "00001", "actors");

console.log(results.items);

while(results.hasNext()) {
  console.log("---▼ Next Page ▼---");
  results = await results.next();
  console.log(results.items);
}

prev( )

Retrieves the previous page of reference query results.

Description

The prev() function retrieves the previous page of reference query results.

The page size is 50 items. Navigate through pages of items with the prev() and next() functions.

If items are added or removed between calls to prev() the values returned may change.

Syntax

function prev(): Promise<WixDataQueryReferencedResult>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.

Fulfilled - A query result object with the next page of query results. Rejected - The errors that caused the rejection.

Examples

Get the previous page of a query result

oldResults.next()
  .then( (results) => {
    let newResults = results;
    let items = newResults.items;
    let firstItem = items[0];
    let totalCount = newResults.totalCount;
    let hasNext = newResults.hasNext();
    let hasPrev = newResults.hasPrev();
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );