How to access to a multi referenced field?

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

Have you read the Wix Support pages about using reference fields?
https://support.wix.com/en/article/referencing-multiple-items-in-one-database-field
https://support.wix.com/en/article/displaying-content-from-multiple-database-collections-using-reference-fields
https://support.wix.com/en/article/working-with-multiple-item-reference-fields

Also, use the search function on this forum as there are many previous posts about this that could be of help to you here.
https://www.wix.com/corvid/forum/community-discussion/reference-fields-with-multi-items
https://www.wix.com/corvid/forum/community-discussion/retrieving-multiple-item-reference-field-using-code
https://www.wix.com/corvid/forum/community-discussion/query-using-a-multi-reference-field
https://www.wix.com/corvid/forum/community-discussion/using-include-function-with-multi-reference-fields

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