How to define related products by group of products

I have followed this guide . But i want define related products in another ways:

  • Products that manually define as same group (New Field) to the current product.


How to change this code for this way?

async function relatedProductsByTable(product) {
let productId = product._id;

// find related products by relation table
let relatedByTable = await Promise.all([
wixData.query(‘relatedProducts’)
.eq(‘productA’, productId)
.include(‘productB’)
.find(),
wixData.query(‘relatedProducts’)
.eq(‘productB’, productId)
.include(‘productA’)
.find()
]);

let relatedProducts = [
…relatedByTable[0].items.map(_ => _.productB),
…relatedByTable[1].items.map(_ => _.productA)
];
return relatedProducts;
}