Forum Documentation Showcase Pricing Learn more

Trouble doing a db search with one to many

Ok, so here goes. i have a db for users and in that db i have a field for companies, so i can assign several companies to a user. when i do a search and try to get all users who are in the current user company i can’t get it to work.

trying to do Type User (company contains current user’s company)

Screen Shot 2020-02-09 at 11.02.04 AM

You have a list of companies on the user data type

Then you are trying to search for a user by saying the company contains the current users company…that is the problem

You should be do a search for users as you are…however you should be using a constraint of current users company list contains this company and then add more to be users list…

so you need a list of users on the company datatype.

1 Like

thanks for the reply. so am i to understand i need to add a field to the company data type called user and add all users that have access to the company their?

yes thats correct

1 Like

@mediamasons You almost have it. Obviously Company is a list of companies since Bubble is giving you the ‘contains’ operator. The problem is that ‘current users company’ is returning a LIST of companies when ‘contains’ is looking for a SINGLE company.

So you need to indicate a specific item. This could look like ‘company contains current users company:first item’ if the current user only has one company.

Or it could be ‘company contains current users company:filtered:first item’ if the current user will have multiple companies and you need to filter it to a particular company.

Either of those options will work if you are searching by a single company. If you want to get users from multiple companies you’ll have to go to the method Boston suggested, do searches merged with searches, or use an advanced filter.

Hope it helps!

1 Like