and() function

So I have the following scenario:

I have multiple toggles.
If a switch is toggled on, show all items of the same type.
If off, don’t show it.

I have the following code:

let filter = wixData.filter();
let query = wixData.query("SHOP");

// Toggle value
let lagerVal = $w("#lagerToggle").value;
let paleVal = $w("#paleAleToggle").value;

let lagerQuery;
let paleQuery;

// Lager
if ($w("#lagerToggle").checked) {
    lagerQuery = query.eq("type", lagerVal);
} else {
    lagerQuery = query.ne("type", lagerVal);
}
// Pale Ales
if ($w("#paleAleToggle").checked) {
    paleQuery = query.eq("type", paleVal);
} else {
    paleQuery = query.ne("type", paleVal);
}

finalQuery = lagerQuery.and(paleQuery);

finalQuery
    .find()
    .then(results => {
        $w("#shopListing").data = results.items;
        //console.log(results.query);
        //console.log(results.items);
    })  
    .catch(err => console.log(err));

The problem is when I run this the query returns 0 items unless only one toggle is checked. I can’t figure out what the problem is. Am I using the and() function wrong or is it not what I think it is?

What I want to achieve is something like this in SQL:
SELECT * FROM table WHERE type = “type1” AND type = “type3” and so on…

Any help would be appreciated. Thanks.

Hi,

and() API is working fine, according to our testing. There seem to be an issue with matching both toggles results. Please, make sure that there is at least one item in the database that fits when both toggles are selected.

Otherwise, it is always helpful to have the link of the website we are discussing, so that we can test and give you the precise suggestions. If you do not want to expose your site here, feel free to reach out to Velo support team via email.

Kind regards,

Kateryna