Forum Academy Marketplace Showcase Pricing Features

Performing a look up to filter the datasource

Hi folks, I need help with search parameters as I fail to get my head around it.

I’m building a list of lodging options. My objective is to display amenities of every hotel room by category.

I’ve:
A table with amenities (e.g. Stove of type Cooking, Solo Bed of type Sleeping, etc.). Types and amenities are in the same table (Table 1):

Title | Type
Stove | Cooking
Couch | Sleeping

A table with listings (e.g. a Hotel Room 1). Each listing has a list of amenities to it for mapping purposes (Table 2):
Room | Amenities
Room 1 | Stove, Couch
Room 2 | Couch

Now to the objective. When I try to display all possible amenities on a page of a listing, it is an easy job - I just return all Listing’s Amenities (e.g. all Amenities of Room 1). That’s quickly done since Bubble allows to look up those things within 1 table.

However, when I want to call only certain amenities by their category, it isn’t obvious. For instance, I want to display a list of Sleeping amenities available in a hotel room 1. This would mean, that I need Bubble to return all Listing’s Amenities (from table 1) that have Amenity Type = “Sleeping” (looked up in table 2). Is there a way of achieving this?

One thing I tried is manual argument entry into a ‘contains’ expression but I found it operational solely when attribute’s type = text, and it doesn’t work with data types…

Thank you!

Hey @daniels.korens if I understand your database setup correctly, you should be able to do something similar to the expression below in a repeating group of data type = amenities.

Do a search for room (constraint: room = hotel room 1)'s amenities intersect with Do a search for amenities (constraint: type = sleeping)

So basically what you’re doing here is fetching two lists; 1) the list of all amenities for Hotel Room 1 and 2) All amenities that are in the sleeping category. Then, you intersect the two lists leaving you with a 3rd list with values that are only present in both of the first 2 lists. Hope that makes sense!

Thank you, it does make sense indeed!
I’ve tried to replicate as per your advice and stumbled upon the issue with utilising constraints in plain text again when this field type = data type (i.e. amenities type is taken from the table 1 (Table with amenities)… This issue doesn’t exist if field type = text, but it isn’t nice this way.

So effectively I can’t make this part happen:

(constraint: type = sleeping)

However, am I missing an obvious way of implementing it? I am attempting to do something obvious like: Type = "Sleeping" where “Sleeping” is just a plaintext string. Should I call it as a parameter somehow, instead of using plaintext?

P.S. Thank you for suggesting an “Intersect with” option, I never knew it!

@daniels.korens I see what you mean. It’s just a matter of cursor placement. The video below should help you set up the search.

Hi @AlexE ! Thank you for the video, it does make it clear, and you are very helpful! However, I tried this before and it still doesn’t seem to work. Can I ask you to confirm what datatype (in db) you have for the field that is used in Constraint?

I suspect the problem is in the following:

  • if the field type is datatype, then you can’t enter plaintext argument. :red_circle: (And in my mind it should be perfectly allowed).
  • if the field is text type (not my case unfortunately), then you can enter plaintext (as the video suggests). :green_circle:

Also it may be due to me not having a subscription :thinking: (Update: quite unlikely)

@daniels.korens in the first table you shared if the Type field is it’s own datatype (let’s say Amenity Types), then instead of typing text into the search you’ll have to do another search there. So just use: Do a search for Amenity Types, with constraint Name = Sleeping

If that still doesn’t work then please share your editor and I can have a look

Hi @AlexE !
Thank you for your continuous help.
Unfortunately additional search doesn’t appear to evaluate well, therefore sharing the links to my editor:

Editor:

Test listing (editor page name = ‘listing’):

As an outcome of this entire task I expect to be able to display amenities categorized by type in the page listing > repeatingGroup amenities (it’s created and you’ll see the expressions there…)

Thank you!

@daniels.korens your data structure isn’t configured in the way I understood from your original post. I’ve modified the search based on how you have your database is set up. Have a look now.

@AlexE this is perfect!!! Thank you so much!

I will post a solution underneath for everyone else to be able to use it -

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.