Displaying related data from 2 databases on 1 screen

I have 2 databases: CUSTOMERS and CUSTOMER_PRODUCTS

  1. CUSTOMERS contain the customer header records such as customer_name, address etc.
  2. CUSTOMER_PRODUCTS contains images and descriptions of the products that each customer sells.
    Both databases contain a unique value for CUSTOMER_ID that logically links the 2 databases together.

So:
On each screen, I want to display 1 customer record from the CUSTOMERS database followed by a gallery of images of that customers products from the CUSTOMER_PRODUCTS database.

Help! Is this possible? I dont find any docs on linking databases together?

Please move this to the questions and answers forum and more will help you asap.

It is possible. You will need two datasets, one for each collection.

On the dataset for customers, set an onReady event. In this event code, ready the customer ID of the current customer using the getCurrentItem() API. Then set a filter to the second dataset, filtering it by the customer ID.

Let me know if this works out for you, will be able to add code snippets only later (working from mobile)

Thanks Yoav. Going to try. Code snippets always appreciated :slight_smile:

Hi Yoav - your advice was good. It works great!

This is how I did it using onReady events for each dataset on the page - in case anyone else is interested:

import {wixData} from ‘wix-data’;
let itemObj;

$w.onReady(function () {
//TODO: write your page related code here…
});

export function artist_ds(event) {
//Add your code for this event here:

itemObj = $w(“#dynamicDataset”).getCurrentItem();
//check what is loaded
for(let key in itemObj) {
console.log( key );
console.log( itemObj[key] );
}
}

export function painting_ds(event) {
//Add your code for this event here:
console.log(itemObj.artist_id)
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“artist_id”, itemObj.artist_id)
)
.then( () => {
console.log(“Dataset is now filtered”);
} )
.catch( (err) => {
console.log(err);
} );
}