Cannot use the or operator in search for constraints

Hi Bubble community!

I’m struggling to incorporate a boolean operator into my constraints for a repeating group.

For context, I have a database of health checks, which are for females, males, or both. I want to create a constraint of type Sex = Current User’s Sex OR “Both”, but I can’t utilise the OR operator. I don’t know why the OR operator doesn’t appear and I can’t figure out any workarounds.

I’ve attached a screenshot of the properties for further context. Any and all help is greatly appreciated!!

Hi! 2 ways I can think of:

  1. You can use the :merged with operator here
    Do a search for Health checks (Sex = Current User’s Sex) merged with Do a search for Health checks (Sex = “Both”)
  2. You can use the :advanced filter to put your filter conditions
1 Like

Use :merged with so the searches will all be done backend and only return the desired results.

An advanced filter will return ALL matching constraints from the Search first, then run the advanced filter client side. So you not only spend more WU but advanced filters on large lists can and will literally slow down your app for your user because it’s doing all the processing in the browser.

2 Likes

Store the value of current users sex as the opposite of what it is. Then use operator of is not (<>) …this will pick up the 2 other options

1 Like

Thanks very much for the solution! I feel like the lack of a simple OR operator in this instance is a serious omission regarding constraint logic.

Also linking @ihsanzainal84’s solution here as to why option one is better than option two.

Cheers!

1 Like

Merged with = OR, albeit with two searches rather than one :slight_smile:

1 Like

Best approach in situations with 3 choices like this is to use the does not equal in constraint as I suggested. It’s just one search, gets same result.

2 Likes

The all round most straight forward way would be to just store it as a List of Sexes, Male and Female, and then you don’t have to handle opposites and the associated UI, can search for Health Checks with one sex, or both (by using two constraints on one search) very easily.

By making an option ‘Both’ it’s kind of over complicating it because Both = Male and Female - so just make it a list that can be Male, Female, or Male and Female.

I think if they’re willing to change the sexes to their opposites then they’d surely be willing to just change the field to a list which is the more standard option

1 Like

I want to create a constraint of type Sex = Current User’s Sex OR “Both”, but I can’t utilise the OR operator. I don’t know why the OR operator doesn’t appear and I can’t figure out any workarounds.

An alternative to using :merged is to define a list of the Sex values you want to use for the constraint, then just use ‘Sex is in’ that list.

You can define that list in a variable somewhere (i.e. a custom state/RG/or RE property), OR you can define it directly in the search constraint.

So:

Sex is in Current User's Sex: converted to list: plus item: Both

or

Sex is in varListOfSexes

2 Likes

Yes, a list field would work.

Best approach in my opinion, add attribute to option set, related to the option set that is opposite. Then use constraint does not equal selected sex option opposite.

One search, no change to data structure or logic to save values, simplest dynamic expression for constraint value.

Always lots of ways to do things.

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