1

I'm trying to list the DataObjects in a class. I want to filter the list of DataObjects based on a conditional query on multiple fields. To select a DataObject based on field1 = xxx or field2 = xxx

For eg: In class Inventory:

+----------------------------------+
| Item  |  Quantity  |  Price      |
+----------------------------------+
| X     |    10      |    30       |
|                                  |
| Y     |    20      |    10       |
+----------------------------------+  

var filter = {
        'Quantity': { '_eq': 10 } OR
        'Price': { '_eq': 10 }
    };

Select Item with Quantity = 10 or Price = 10. How can achieve this?

1 Answers1

2

The best way to do this would be to break up your query into two separate calls and combine them. Syncano uses AND to combine queries, so for OR you would have to separate them into two separate API calls.

// v1 Syncano JS SDK
var Syncano = require("syncano");  // CommonJS
var connection = Syncano({accountKey: "ACCOUNT_KEY"}); // or API Key
var DataObject = connection.DataObject;

var list = {instanceName: "INSTANCE_NAME", className: "CLASS_NAME"};
var filter1 = {
    'Quantity': { '_eq': 10 }
};
var filter2 = {
    'Price': { '_eq': 10 }
};

var QtyArray = [];
var PriceArray = [];

DataObject.please().list(list).filter(filter1).then(function(res){
    // res is an array of filter 'Quantity'
    QtyArray = res;
});

DataObject.please().list(list).filter(filter2).then(function(res){
    // res is an array of filter 'Price'
    PriceArray = res;
});

var comboArray = QtyArray.concat(PriceArray);
  • that seems like a simple solution but I was looking to make this possible with one call instead of 2. Also, this solution will require an additional logic of removing duplicate entries added from both the arrays. – Shefali Agarwal Apr 17 '16 at 08:38