I’ve got a messy filtration logic flow that I’ve been working to get off of advanced filters as much as possible, since what it filters against can scale indefinitely. Throwing this out there for those who need to mix their ANDs and ORs inside a DB query.
Imagine the basic SQL query
Select *
From Table FOO
Where
A = B
AND C = D
AND (X = Y
OR X = Z)
This is doable in Bubble via a basic merge action:
Do a search for FOO
Constraint
A = B
C = D
X = Y
: merged with
Do a search for FOO
Constraint
A = B
C = D
X = Z
(It takes a slight performance hit because the MERGE is actually done server-side and not on the DB core.)
But what about a query with multiple OR conditionals? Such as:
Select *
From Table FOO
Where
A = B
AND C = D
AND (X = Y
OR X = Z)
AND (AA = AB
OR AA is empty)
As you can imagine, this is impossible with a vanilla MERGE. It would end up having to be 1 Search For query merged with a second INTERECTED with a 3rd and then merged with a 4th, which is actually logically impossible in Bubble due to its left-to-right execution. You’d have to store intermittent results in an RG on-page, which starts becoming poorly performant real fast when sets creep into the 1000’s. (And this is impossible on backend workflows, unless you stuff temp tables via recursive API’s to perform injections off of lists… see you next epoch)
Anyway. The solution used to be very simple when Bubble allowed “unique_id IS IN” constraints. That took that away for some reason, so the new trick requires anything that maintains a 1:1 relationship with the table you’re querying. An example would be your table having a User value and your User table having a value for the queried table, and each can only have one of the other. If your query table doesn’t have this, then you can construct what I call a “reflective table”: a table that contains just an attribute of the type of table you’re querying against, as well as an attribute of that same reflective type on your original query table. Like a feedback loop. And everytime you instantiate an object on your query table, you (1) also place one reference to the new object on this reflective table and then (2) update your query table also with the reference to this reflective object.
Then you can perform the following solution to he above problem:
Do a search for FOO
Constraints
A = B
C = D
{FK or 1:1 reflective column (USER, reflective_column, etc)} is in (Do A search for same column
constraint FOO is in (Do A search For FOO constraint X = Y :merged with Do A Search For FOO constraint X = Z)
)
{Any unique FK or 1:1 column (USER, unique_id, etc)} is in (Do A search for same column
constraint FOO is in (Do A search For FOO constraint AA = AB :merged with Do A Search For FOO constraint AA is empty)
)
And so on. You can perform unlimited nested OR conditionals into a single query and Bubble surprisingly executes this fairly performantly.