Hello,
I have a Multi referenced field in my collection database but I can’t access it from dataset.
But also in code I am not able to see the property name, when console.log(it)
I should able to see even an array of _id or directly the object referenced.
Could you please explain me why? Do you have a workaround?
1 Like
OK So sadly You cannot use multi reference fields with datasets. Datasets do not fetch these fields in the current API. The only way you can access multi-reference fields is using the wix-data API. There are two ways to do this:
$w('#dataset6').onReady(() => {
let currentUser = $w('#dataset6').getCurrentItem();
console.log(currentUser);
wixData.queryReferenced("Candidate", currentUser._id, 'languages')
.then((results) => {
console.log(results);
})
});
- Using the query() function with include()
$w('#dataset6').onReady(() => {
let currentUser = $w('#dataset6').getCurrentItem();
console.log(currentUser);
wixData.query("Candidate")
.eq('_id', currentUser._id)
.include('languages')
.find()
.then((results) => {
console.log(results.item[0].languages);
})
});
This is a very smart solution to an obvious shortcoming. Here you are using the dataset to filter and sort and the collection to pick up the references unattainable via the dataset api. Nice work.
1 Like