Determining the DB type of an object

My app has scenarios where an object passed to a function might either be from the DB or OnlineDB.

When trying to write one function to handle both cases, I receive the error Cannot add an object in OnlineDB to a batch in DB.

How can I create a batch based on the object passed to the function?

1 Like

This was solved by using a hidden property of the DB object

function doesThings(some_object) {
    var _DB;
    switch (some_object._adapter._description) {
        case 'DB':
            _DB = DB;
            break;
        case 'OnlineDB':
            _DB = OnlineDB;
            break;
        case 'LocalDB':
            _DB = LocalDB;
            break;
    }

   var batch = new _DB.Batch();
}
3 Likes

Iā€™m not sure hidden properties like this will always be available, so be sure to test your app on beta or RC runtime releases.

1 Like