Hi! I’m running multiple queries for different databases/collections, and I need to pass them to one repeater. The closest I get is to send only the first array of results, but the others are not passed to (knew this could happen but had to try).
Nothing happened haha. Alternatively, I’ve also been looking on wix documentation and this forum for a way to run ONE query for all the databases I need, but only found something about a new feature wix is developing and it might do what I want. In the mean time, does anyone know a way to achieve this? Or maybe a workaround, using datasets and the .getCurrentItem but I think it would lead me to the same issue, which -in short- is to pass ALL the results to the repeater.
Yet I’m not confortable with the code, you see I need to run the query for 18 collections, and it will be quite large. I think it would be more efficient to loop through all of them, and I’ve been trying to do so since yesterday but I got a little confused and figured I should stop for some time. Anyway, today I’m going back to it with a fresh mind. I’m pasting the code (or the attempt of it haha) below so maybe you or someone can help me taking a look, maybe you come up with some idea.
“Collections” contains all the names (I’m only using three of them until I got the code right)
“Results” will contain every query result
I created a function that runs the query => I’m pretty sure here lies my confusion
I use .forEach to perform the runQuery function on each of the “Collections” elements and once it’s done the repeater gets the results.
The error I get is that the query won’t run, and it makes sense since I’m not able to tell it to pick just one of the “Collections” elements. I guess I need to create a for items loop inside the function too, I’ll try that and see what happens. I’m not a coder so I might be using the wrong syntax, sorry! But this is my approach, if you or someone reading this think there is a better one it would be great if you could share it with me, or if you think this way should do the trick but help me spot whatever is it that I’m missing it’s fine as well. Thanks!
I’m also trying to combine multiple queries into one repeater and I’m having trouble getting it to work… Basically I have an “Event Photos” collection with a many-to-many relationship with a “Categories” collection. I just want users to be able to search for “Event Photos” and have the results also be filtered by the “Categories” reference field. So for example, if someone types “Corporate” into my search box, all event photos with the word “Corporate” in the Categories reference field would be returned. I really wish reference fields could be included in the same query!!
Any way, here’s what I have so far… Could you help me since you were able to make it work for yourself?
I haven’t solved it yet! Thank you for responding. I would love your help. I’m not sure if concat is going to be the best solution for me, since I really only want results to show items from my events table (table 1) - I just want those items to be searchable by their referenced/related “categories” (table 2) as well. Thank you SO MUCH for your help!
export function searchbutton_click_1(event) {
wixData.queryReferenced(“EventPhotos”, $w(“#searchbox”).value, “Categories”)
.then((results) => { let ResultsPic = results.items;
$w(“#searchedrep”).data = ResultsPic
$w(“#searchedrep”).expand();
})
. catch ((err) => { let errorMsg = err;
});
}
I haven’t tested it, but let’s see if it works or at least gets you on the path. Please, check if “EventPhotos” and “Categories” are exactly written as your collection’s names. Let me know how it turns out!