Looking up a relationship in reverse?

New to bubble and building a demo app for myself to learn more.

I have a simple data model with Users & Homes. A User can have a Home.

On the User table, I have a field with a relationship to Home. I do not have a field on the Home table to point to the users.

I’m trying to have a listing of all the Homes. I would like to be able to load information about a Home AND include which User(s) have that home associated with them.

Is there a way to make this information available for both the User object and the Home object?

Thanks. Hope this makes sense to the bubble-pros out there!

Yep, create a repeating group (RG) with source User and have it do a search for Users based on a Home. If you want to show the Users within a RG of Homes, then put that User RG into the Home RG cell and have it reference the current cell’s Home as the source for the search (note that an embedded RG like this this can result in a slower population of results if your data set is big).

Or if you only want to show Users in a details view for a Home, then just have the User RG reference the Home being displayed.

Note that there is some debate on whether you should also have a “Home” field listing the Users associated with the home. It really depends on the nature of your dataset and how you are going to search and display it.

For me, if you only are going to list the Users in a details view on a Home, I would have created the same database setup you have. If however you want to list a Home’s users in a table of Homes, then you may want to explore linking both ways if your test app isn’t running fast enough.

You can read all about those issues here… Alternative approach to the Bubble’s recent tutorials for list of things

PS: if you are looking to dig deeper into understanding Bubble database setup and the impact on speed, I highly recommend this book: The Ultimate Guide to Bubble Performance - 156 pages of optimizing tips

2 Likes

Ahh ok. That’s interesting and that does the trick.

I’ll do some more reading. I may just try to set it up in a way where the relationship is on both “tables” I (hope) it’s easy to keep that data in sync having it in both places?

It’s not super hard to keep them aligned, but it’s harder than just having it linked on one side. Any workflow you build to update a record has to now update both. And you’ll need to have a way to check that everything lines up.

The only value I see to linking both ways (User as a list field within Home) is if:

  1. There aren’t that many Users associated with a Home
  2. You’re planning to show long lists of Homes with their Users displayed in that list
  3. And/or you want people to be able to search for Homes based on associated Users

In that case the performance improvement of having the Users already within the Home record (vs. having to do nested searches or nested RGs) should outweigh the bloat that comes from Home records being more data heavy. Again, this assumes that there aren’t that many Users associated with a home. Bubble and others say that long list fields are bad.

Best thing is to build some dummy records and screens and see how they behave.