DB query filtered by comparison of two fields?

Hi @jwyrick

Unfortunately you cannot do that kind of comparison in a JourneyApps DB query.

Your options are

  • Store and update the calculated value in the DB and then query on the calculated value, e.g. DB.account.where('unused > ?', 0)
  • Pull in all the objects into an Array and then do a custom array filter in JS.
    (Please note, if your comparison logic needs to read data from associated objects you will need to first pull those objects into memory, see this post for an example but with a sort function. However, if your comparison logic is just going to use fields directly on the objects then you will be fine)

In essence the latter is what you would have wanted the query to do, as the DB would need to compare each record with itself, as opposed to comparing it to some static query value.

I hope this helps.