TypeORM activeRecord style query for "where (a & b) or (c & d)"?

995 Views Asked by At

I want to use TypeORM to run a query like

... WHERE (a=1 && b=true) OR (a=2 && b=false)

I see a bunch of references to doing this in the QueryBuilder style, but I need to know how to do this using the ActiveRecord style.

1

There are 1 best solutions below

0
doub1ejack On

You can do this by providing an array of objects to the where: property:

Item.find({
    where: [
        { user: { id: userId }, confirmed: "true" },
        { user: { id: userId }, status: "active" }
    ]
});

The query above would find items that belong to a user where

  • user matches user id AND is confirmed, or...
  • user matches user id AND is active