I need some help with a database query… Basically I have three collections, an “events” collection has a one to many relationship with both my “tags” collection, and my “categories” collection. I have a search box query running beautifully, but I just discovered that it doesn’t actually query my categories and tags reference fields. Help! I tried using an .include(), but it didn’t help. And, what’s more, I know you can’t use an include() with more than one multi reference field (both my reference fields are multi-select). I’m totally lost looking at trying the queryReferenced thing. This is what I have so far:
In your above code you are only querying 1 collection called " EventPhotos ". You are querying 3 field keys (columns) in that collection. If this is what you are indeed trying to do and you want to filter your repeater for the results then code something like this…
export function searchbutton_click(event, $w) {
//change to the correct ID for your dataset
$w(“#dataset1”).onReady(() => {
Hi Mike, that is what I’m trying to do, but I also want it to filter my results by my reference fields… So, for example, my “categories” field is a field in my “event photos” collection that references another collection with multiple categories. I just want the query to also be able to filter by those values, so that when a user types in a category, the results will show any “event photos” that belong in that category. Is that what the “set filter” function will do? The way I’ve tried it before it gives me an error telling me that my reference fields can’t be set to null or undefined.
@mikemoynihan99 I suppose not? I’m sorry, I guess I’m just not understanding why it shouldn’t be able to be filtered by a reference field… I am just trying to show results from one dataset from one collection (I think), but I want to be able to filter those data points by a reference field. My “event photos” and “categories” are two separate collections, they have a many-to-many relationship, I just want users to be able to enter any search they wish, including terms that correspond to the related “categories,” and have it turn up results from my “event photos” collection.
so with my above filter example you could for instance filter field keys relatedJob, eventDate, jobDescription.
as your dataset is only connected to " EventPhotos ", you can only filter the " EventPhotos " collection, i.e. if the " EventPhotos " collection has 1000 rows of data the max number of rows you can filter is 1000. You can not filter more than the 1000 rows.
If what you are wanting to do is return results from more than 1 collection code separate wixData.query for each collection and concatenate the results for each to make one list of results.
Ohhhh, okay, I will go try that. Thanks very much for your help. I’m familiar with configuring interconnected databases, but not with code so much, so this is a steep learning curve for me.
Well Mike, this is what I have so far… I can get it to display results from the “Event Photos” database, but not from “Categories.” Is there not a way to convert the reference field value into a string or plain text so that the query would work on it? It just seems so wild that there isn’t a way for it to easily query the reference field on the one database I want to see results from.
@mikemoynihan99 Thanks! But then how do I get them to display in the repeater the same? Because wouldn’t the results from the “Category” dataset not look like my “Event Photos” results?
@mikemoynihan99 I’m still struggling with this same issue… Can you please help me out?
Basically I’m just trying to make my referenced field be accessible in a query. I’ve tried using the include() function, the query referenced function, but nothing is working.