I have a repeater which has data populated from a wix query.
let uid = wixUsers.currentUser.id;
wixData.query("PhoneMatches")
.include("matchAData", "matchBData")
.find()
.then((results) => {
$w("#repeater3").data = results.items;
$w("#repeater3").expand();
})
$w("#repeater3").onItemReady(($item, itemData, index) => {
// get the partner's data
let data = itemData.matchAData;
if (itemData.matchA === uid) {
data = itemData.matchBData;
}
console.log(data);
});
This code works perfectly fine when I preview the website. In the console log, I see that the referenced data has been queried properly and it shows a dictionary.
However, when I look at the published site, when that data is printed, it is still the ID and not the dereferenced data. I’m thinking this is because it has not yet derefenced it. If so, how would I wait for this to finish? Or, what could be the reason that it does not dereference?
You should take a look at this …
https://russian-dima.wixsite.com/meinewebsite/how2-include
The RESULTS of INCLUDE and THE RESULTS of FIND are NOT the same!
They have different-result-structure.
When querying a collection that contains a reference field without using the include() function:
Single reference field: returned items contain only the ID of the referenced item, and not the full referenced items.
Multiple reference field: returned items do not contain the multiple reference field at all.
Perhaps you should also check the permissions of your database!
When everything is working fine in the PREVIEW and NOT in LIVE, it is the first sign, that you have not the permissions to get data from your SECURED/CLOSED-DB.
Another reason could be that you have data in your SANDBOX, but did not sync the data of your DB with your LIVE-DATA.
The databases have full access to anyone for all operations. Also I’m not sure what you mean for the first part. I am following the API documentation, which states include() is used as follows:
wixData.query("myCollection")
.include("referenceField")
.find()
Also my problem is that the data shows up as the ID. However, I used the include() call so I expect that data to be a dictionary with all the of values in the collection row it references. Apologies if this wasn’t clear.
@pranav-patil
Yes! And this is why a gave you the link to my very good described “include-totorial” (on my opinion).
Also use the CONSOLE and analyse the RESULTS of include. You will find differences to the results of —> .find().
And then you will be able to understand whats going wrong.
Yes, it’s exactly what you get, the issue with the ID.
Sorry, after further investigating, syncing the live data to the sandbox results in the preview also failing. You correctly pointed out that this was a discrepancy. Thank you!
@pranav-patil
ok. Glad that i could help you.
Do not forget to like it, if you really liked it.
Good luck and happy coding.