Seeking Help: Displaying Dynamic Price Ranges for Apartments with Shares for Sale


I’ve recently started working with Bubble and I’m looking for a solution to a problem that’s been blocking me for days…

Explanation: I have apartments that are divided into shares, the number of shares is immutable. For example, Apartment A has 10 shares, each with a different value.

I have 2 tables in my database:

  • “Property”: contains apartments, each unique, with information such as the apartment’s name, its address, and a list of shares for that apartment.
  • “Shares”: contains the shares, each unique with its own ID. This also includes the price of the share, whether the share is for sale or not, and the property ID to which the share refers.

It is mandatory that each share has its own ID and is listed independently.

I want to display in a repeating group, each apartment (only if there are shares of that apartment for sale), the price range of a share (min-max), and the name of the apartment.

I’m sure it’s not complicated but I can’t do it. When I set the source of my repeating group to the “Property” table, I can’t find the prices because the ID of the shares is in list format. When I set the source to “Shares” and group by on the “Property” ID, I’m also stuck for the prices.

Thank you for reading, I hope I’ve explained my problem as simply as possible and if someone can help me out, that would be great!

Hmm. It’s tough to grasp the full situation without screenshots…but you have provided some pretty good detail to take a stab:

Can you change the data source of your repeating group so it searches for all shares that are for sale, :each items Property, :unique elements

That way you’ll show all properties that have shares for sale. And within that repeating group, you can have another that displays all shares linked to current cells property.

1 Like

The approach above would work well. Another solution is a database trigger which can be useful in cases like this.

Create a database trigger on the Shares data type. When the Share is modified/created, make changes to Share’s Property’s numberOfSharesAvailable (this is a number field on the Share’s Property). Set that to Share’s Property’s List of Shares:filtered (available = yes):count

This will keep a field on the Property data type that is always equal to the number of shares available. Whenever a share is modified/created, it’ll update that number. This doesn’t have severe WU implications as a number field is virtually negligible in terms of data size, and the backend triggers would be cheaper WU than doing some advanced filtering shenanigans. It’s likely cheaper than @mac2 's approach because using his you have to return all of the Shares that are available for every property, and the Properties themselves. With my approach, whilst there’s WU in updating the share count, that’s likely to be rare for your use case and it means you only need to return the Properties to fill the RG.

DB triggers are great and underutilized :grin:

1 Like

Thank you so much for your help! I finally found a solution with group by, nut yours advices help me so much.