I can't figure out how to get field values from joined collections. How do you do this in wixData.Query( ) and in $w("#myDataset").setFilter( ) scenarios?
It looks like '_items' collections that are returned hold a 'ref' field with an internal primary key to the referenced collection, but I do not know what to do with that?
Thanks!
Don't you just love it when you are searching for something... and someone has the solution but they don't help you???
Hi Christine,
could you share the code with the solution for your problem?
Thanks in advance !!
I figured out how to get it to work!!!!!!!
Hey Or, were you able to figure out if the setFilter function works on reference fields?
darn.. yea, that's what I had before and it wasn't working
Hi,
First thing is that you need to change the filter for an input that is equal to the "university" field and not "_id" like this:
$w("#dataset2").setFilter( wixData.filter() .eq('university', $index));}
I checked it out and it doesn't work, i'm afraid it is because the setFilter function doesn't work on reference fields, I will give you an answer soon.
https://syverts2.wixsite.com/mysite
Hi Christine,
Can you please share a link to your site so i can inspect?
Roi
Hi Roi,
So in mine I'm trying to link a dropdown ("dropdown1") to set a filter on a dataset's reference field.
export function dropdown1_change(event, $w) {
let $index = $w("#dropdown1").value;
if ($index === ""){
$w("#dataset2").setFilter( wixData.filter());
}
else{
$w("#dataset2").setFilter( wixData.filter()
.contains('_id', $index));}
}
Christine
Hi Christine,
Can you please share your code ?
Roi
Hi Ben,
Try this:
wixData.query("CoursePrograms").eq("_id", id).find();
Please update us with your progress.
Roi
Am having a similar issue at the moment with a filter. Wish I could help... Sometimes it helps to know we are in the same boat!
Please help - I am stuck and need to keep moving. Thanks!
This is somewhat helpful - thank you. However, I am still struggling. I have 2 collections: ProgramTypes and CoursePrograms. ProgramTypes is a lookup collection. CoursePrograms has a reference back to ProgramTypes (via a Reference field named 'Program'). My code has the '_id' from the ProgramTypes collection already. Now, I need to query the CoursePrograms collection where the Program.ref = [my _id].
var id = "ABC123"; //_id from ProgramTypes
wixData.query("CoursePrograms").eq("program.ref", id).find();
This does not work. How can I get this working?
Thanks!
Hi,
That ref is "_id" field of the item in the referenced collection.
You can use wixData.query("nameOfCollection").eq("_id",the ref that you received).find()
And then you get the item from the referenced collection.
Roi