Question:
I’m looking into how to query multiple collections at the same time.
Product:
I’m using Studio Editor
What are you trying to achieve:
I have 2 collection equipment and sale.
the sale collection contains the fields “isActive” and “defaultPrice”
The equipment collection contains a field “city”
const isActive = wixData.query("sales").eq("isActive", true)
const minPrice = wixData.query("sales").gt("defaultPrice", $w('#minPrice').value)
const city = wixData.query("sales").contains("**equipment.city**", "Saint")
I’m trying to get the query into a repeater. is there any way I can query a referenced field?
Certainly. According to the Velo API reference:
If the collection that you are querying has references to other collections, by default, the data from referenced collections will not be retrieved. To get the data from the referenced items, you must either use the include()
chained function before find()
or use the queryReferenced()
function instead of query()
.
Thanks Pratham. I successfully built numerous grid with the included statement. Sorry I should have mentioned this. here’s my full code:
The grid shows results except for adding the “equipment.city” query.
const isActive = wixData.query("sales").eq("isActive", true)
const minPrice = wixData.query("sales").gt("defaultPrice", 2)
const city = wixData.query("sales").eq("equipment.city", "1")
const myQueryResult = await isActive
.and (city)
.and(minPrice)
.include("equipment")
.descending("_createdDate")
.find();
const myData = myQueryResult.items
$w("#repeater2").data = myData;