Hook afterQuery inconsistent/not working for me

Hello.

I have a very simple situation. I have a “Houses” collection with many fields, and one of those fields is a Reference (single item) to another collection “Currency”.

On a dynamic page (or any other page/function for that matter), I want to be able to obtain the item from “Currency” collection, using the reference on the “Houses” collection.

I want this to be done on the Backend.

I thought these 3 functions could work:

wixData.get               // seems to work
wixData.query             // seems to work
wixData.queryReferenced   // does not work for single item references (???!!!!!!)

My problem is that wixData.get and wixData.query does not seem to be working on the afterQuery hook, it only works consistently (always) on Frontend code.

I made 2 simple test codes, one in the Frontend code, and one in the Backend code, to show this behavior.


TEST 1 - Same code on Frontend and Backend
Frontend:

import wixData from 'wix-data';

$w.onReady(function ()
{
   $w("#dynamicDataset").onReady(() =>
    {
        const item = $w("#dynamicDataset").getCurrentItem();

        wixData.get("Currency", item.currency).then((results) =>
        {
            console.log("wixData.get works Frontend -> " + results.symbol);
        } ).catch((err) =>
        {
            console.log("wixData.get error Frontend -> "  + err);
        });

        wixData.query("Currency").eq("_id", item.currency).find().then((results) =>
        {
            console.log("wixData.query works Frontend -> " + results.items[0].symbol);
        } ).catch((err) =>
        {
            console.log("wixData.query error Frontend -> "  + err);
        });
    } );
} );

Backend:

import wixData from 'wix-data';

export function Houses_afterQuery(item, context) {
 
    wixData.get("Currency", item.currency).then((results) =>
    {
        console.log("wixData.get works Backend/hook/afterQuery -> " + results.symbol);
    } ).catch((err) =>
    {
        console.log("wixData.get error Backend/hook/afterQuery -> "  + err);
    });

    wixData.query("Currency").eq("_id", item.currency).find().then((results) =>
    {
        console.log("wixData.query works Backend/hook/afterQuery -> " + results.items[0].symbol);
    } ).catch((err) =>
    {
        console.log("wixData.query error Backend/hook/afterQuery -> "  + err);
    });
 return item;
}

Log results:
First time I hit the “preview” button (backend works):

wixData.query works Backend/hook/afterQuery -> $
wixData.get works Backend/hook/afterQuery -> $
wixData.get works Frontend -> $
wixData.query works Frontend -> $

Second time I hit the “preview” button (backend does not work):

wixData.get works Frontend -> $
wixData.query works Frontend -> $ 

TEST 2A - Backend code only, same code as previous test
Frontend:

$w.onReady(function (){} );

Backend (same as TEST 1):

import wixData from 'wix-data';

export function Houses_afterQuery(item, context) {
 
    wixData.get("Currency", item.currency).then((results) =>
    {
        console.log("wixData.get works Backend/hook/afterQuery -> " + results.symbol);
    } ).catch((err) =>
    {
        console.log("wixData.get error Backend/hook/afterQuery -> "  + err);
    });

    wixData.query("Currency").eq("_id", item.currency).find().then((results) =>
    {
        console.log("wixData.query works Backend/hook/afterQuery -> " + results.items[0].symbol);
    } ).catch((err) =>
    {
        console.log("wixData.query error Backend/hook/afterQuery -> "  + err);
    });
 return item;
}

First and second time I hit the “preview” button (backend does not work, empty log):

 // (empty log, ok for frontend without code, not ok for backend with code)

TEST 2B - Backend code only, removed wixData.query code
Frontend:

$w.onReady(function (){} );

Backend (removed wixData.query code):

import wixData from 'wix-data';

export function Houses_afterQuery(item, context) {
 
    wixData.get("Currency", item.currency).then((results) =>
    {
        console.log("wixData.get works Backend/hook/afterQuery -> " + results.symbol);
    } ).catch((err) =>
    {
        console.log("wixData.get error Backend/hook/afterQuery -> "  + err);
    });

 return item;
}

First time I hit the “preview” button (backend works):

wixData.get works Backend/hook/afterQuery -> $

Second time I hit the “preview” button (backend does not work, empty log):

 // (empty log, ok for frontend without code, not ok for backend with code)

I find this problem very unintuitive and disappointing. Already lost like 3 days of work without being able to solve it. Documentation and forum questions about this are very poor (especially about queryReferenced, nowhere it states that it does not work with single referenced items!).
Sadly, I will need this kind of functionality for more complex uses of my website, and if I can not solve/understand this issue, I will have to find another platform to use :frowning:

Does anybody know what am I doing wrong?

Thank you!

https://support.wix.com/en/article/corvid-about-data-hooks-for-dynamic-pages
https://support.wix.com/en/article/corvid-creating-data-hooks-for-dynamic-pages