vish.Net
vish.Net

Reputation: 962

Sails Waterline "Or" clause not working

I tried a lot of time to figure out getting an OR clause working in sails without success.

I am using Sails-MySql adapter.

Have anyone of you done anything like this already? I would appreciate some help.

Basically this is what I want to do:

Do an OR clause on a set of fields along with an AND on another set of fields.

Something like this:

FdbDevice
  .find()
  .where(or:
    [
      { deviceCategory: “cardiology valve bioprosthesis” },
      { deviceCategory: “nephrology haemodialysis catheter” }
    ]
  })
  .where(
    { catalogNumber : “Z286004” },
    { modelNumber: “Z286004” }
  )
  .exec

Upvotes: 1

Views: 166

Answers (2)

jhonny lopez
jhonny lopez

Reputation: 325

you can try something like that, into the find:

  FdbDevice
      .find({or:
        [
          { deviceCategory: “cardiology valve bioprosthesis” },
          { deviceCategory: “nephrology haemodialysis catheter” }
        ]
      })
      .where(
        { catalogNumber : “Z286004” },
        { modelNumber: “Z286004” }
      )

Upvotes: 1

Yann Bertrand
Yann Bertrand

Reputation: 3114

In this particular case, here is how I would do it:

// Each element in the array is treated as 'or'
var possibleDeviceCategories = [
  'cardiology valve bioprosthesis',
  'nephrology haemodialysis catheter'
];

FdbDevice
  .find({
    deviceCategory: possibleDeviceCategories,
    catalogNumber: 'Z286004',
    modelNumber: 'Z286004'
  })
  .exec(cb);

Check out the docs for more informations about the Waterline's query language.

Upvotes: 2

Related Questions