How to JOIN 2 queries with _id reference field

Hello,

This code below creates two WIX queries perfectly for me:

    // Get ALL Menu Items --------------------------------------------------------------------
    // Returns 20 rows with fields: _id, title, photo, description, menu, etc...
    let myMenuItemsQuery = await wixData.query("MenuItems")
        .find()
    
    // Get WishList Items for this User ------------------------------------------------------
    // Returns 3 rows for current user with fields: _id, userId, menuItem (reference field)
    let user = wixUsers.currentUser;
    let myWishlistQuery = await wixData.query("Wishlist")
        .eq("userId", user.id)
        .include('menuItem')
        .find()   

    // How do I JOIN these into one query that I can use to populate a repeater? ------------

    // Display Query Results ----------------------------------------------------------------
    console.log("***** Menu Items ", myMenuItemsQuery)
    console.log("***** Wishlist Items ", myWishlistQuery)

Now I need to JOIN them such that I get:
* ALL items in myMenuItemsQuery (20 items in example)
* JOINED to myWishListQuery (filtered for current user) on menuItem._id
* so that I can tell which items in the myMenuItemsQuery are on the wishlist

An example is that:
* Menu Item “Blueberry Pie” has an _id = 1064e51c-8874-40dc-ac6b-88d41f8cd51d
* MenuItems._items._id = 1064e51c-8874-40dc-ac6b-88d41f8cd51d
* Wishlist._items.menuItem._id = 1064e51c-8874-40dc-ac6b-88d41f8cd51d

Ultimately, I need a query with ALL menu items and then a flag to tell me if that particular item is in the user’s wishlist.

How would I go about creating this join?

Thanks, Jason

Perhaps this will help you…

let obj1 = {"firstname": "Riccardo"}
let obj2 = {"lastname": "Pablos"}


$w.onReady(()=>{
    let assigned = Object.assign(obj1, obj2); console.log(assigned);
    let merged = {...obj1, name:{...obj1, ...obj2}}; console.log(merged);
});

Thank you for your response, but I tried this and it didn’t seem to resolve the issue. Let me be more specific:

I need to use wixData to create the following SQL Statement:

SELECT Columns from both Collection MenuItems and Collection Wishlist
INNER JOIN them based on MenuItems._id = Wishlist.menuItem
WHERE Wishlist.userId = Current User’s ID

For Example:

SELECT MenuItems.[ID], MenuItems.Title, Wishlist.[User Id], Wishlist.MenuItem
FROM MenuItems INNER JOIN Wishlist ON MenuItems.[ID] = Wishlist.MenuItem
WHERE (((Wishlist.[User Id])="ec7e15a3-537b-4236-8807-dd97ba553c0a"))
GROUP BY MenuItems.[ID], MenuItems.Title, Wishlist.[User Id], Wishlist.MenuItem;

How can I do that?

Thanks for any help or suggestions.