I have two tables Stores and Favorites. The favorites table contains some stores’s ids. I’m trying to find the only stores that are existed in the favorites table but the following didn’t work, any idea why? maybe because “data.favorite.linked_item_id” is an array, but how to solve it.
SELECT(data.stores, item.id == data.favorite.linked_item_id)
I have solved it as following:
SELECT(data.stores, IS_IN_ARRAY_BY_KEY(data.favorite, “linked_item_id”, item.id) )
- linked_item_id represent the store’s id number in Favorite Table.
But, what if I have a complex condition based on two criteria, suppose that I have two types of favorites, so, I’d like to get the stores which are in the favorite table AND the favorite_type == “stores”.
- SELECT stores where stores.id == favorite.linked_item_id AND favorite.favorite_type ==“stores”
In the case IS_IN_ARRAY_BY_KEY is not enough.
You can indeed combine conditions in a SELECT filter. From the documentation:
SELECT<product, position>(products, position < 2 && product.category == "Utility")
If for some reason this is inconvenient, you can also achieve AND type conditions by nesting SELECT filters.