I've been coding applications for many years in a form of Basic, however I am new to both Wix coding and Java Script.
I have two collections with a many-to-many relationship. A. is a Category collection (business sectors), B. is a Business collection (individual companies).
Collection A. has a multi-reference field called Business which includes all the Businesses associated with a given Category.
I wish to display all the businesses for a selected Category using the queryReferenced() statement:
let names = await wixData.queryReferenced("Category", $w("#Category").value, "Business");
“Category” = Collection Name
“#Category” =Selected Category
“Business” =Multi-reference field name
names =list of business names in the Business multi-reference field
Are the above parameters correct?
I am using a repeater field to display the businesses.
Can anyone show me what the code looks like to insert the ‘names’ variable into the page to display the businesses using the repeater field.
Thanks in advance.
Gerry
Here's an example that will certainly help:
Multi-Reference Query
Query multiple-item reference fields and display the results in a table.
Hi,
You can use a simple query function and pass ID of the categories you want, without having to use queryReferenced. Have you tested it yet?
It’s something like this:
import wixData from 'wix-data'; wixData.query("business") .eq('categoryReferenceField', 'categoryId') .find() .then((results) => { console.log(results.items) }) .catch((err) => { let errorMsg = err; });
So, you can learn more about Query functions here: https://www.wix.com/code/reference/wix-data.html
Hope it helps ;)