Database Search with many Input and Reference

Hi Team,
I have 2 Database (Artists and Books)


db_Artists

  • Artist_Nickname
  • Artist_FirstName
  • Artist_LastName

db_Books

  • Book_Name
  • Book_Category
  • Artist_Nickname (reference to db_Artist.ArtistNickname)

I have a page with a grid/Repeater that list all the books (Linked to my dataset db_Books. (This work fine)

In this page, i have 2 “TextInput” box. (Input_BookName, Input_Category) and a search button (With code) to filter the contain of the grid based on these 2 inputs. (This work also fine)


The Code for the search button:

import wixData from ‘wix-data’;

export function searchButton_onClick(event) {

wixData.query("db_Books") 
    .ascending('Book_Name') 
    .contains('Book_Name', $w('#input_BookName').value) 
    .contains('Book_Category', $w('#input_Category').value) 
    .find() 
    .then(res => { 
        $w('#repeater1').data = res.items; 
    }); 

}


My question :
I would like to add a DropDown Input, list all the artists, and add this filter to the same button.
I tried many ways( Contains, eq, …) , but, because the “Artist_Nickname” is a reference fields, i can’t get it working.

How should i format my Query/code to get this done ?

Thanks

Hi,
Use query to get the artist’s name from the artists collection and compare it with another .eq in your search query.

Let me know if you need further help,
Or

Hi I’m trying to do the same thing, but I’m not sure exactly how to format the code… Can you please help me? I tried to use the .includes() function, but it didn’t work for the query.

My code so far:

import wixData from ‘wix-data’;

$w.onReady( function () {
$w(“#searchedrep”).onItemReady(($item, itemData, index) => {
$item(“event”).text = itemData.relatedjob;
$item(“#description”).html = itemData.jobdescription.substring(0, 225) + ‘…’;
$item(“#thumbnail”).src = itemData.thumbnail;
$item(“#thumbnail”).link = itemData[‘link-EventPhotos-relatedjob’];
$w(“#thumbnail”).clickAction = “link”;
})
});

export function searchbutton_click(event) {
wixData.query(“eventphotos”)
.contains(“relatedjob”, $w(“#searchbox”).value)
.or(wixData.query(“EventPhotos”)
.contains(“jobdescription”, $w(“#searchbox”).value))
.or(wixData.query(“EventPhotos”)
.contains(" categories “, $w(”#searchbox").value)) <---- reference field
.or(wixData.query(“EventPhotos”)
.contains(" tags “, $w(”#searchbox").value)) <------ reference field

    .find() 
    .then((results) => { 
        $w("#searchedrep").data = results.items; 
        $w("#searchedrep").expand(); 
    }); 

}